一、系统环境

  1. [root@VM-0-3-centos ~]# cat /etc/redhat-release CentOS Linux release 7.1.1503 (Core)

二、MySQL安装执行下面语句安装MySQL

  1. [root@VM-0-3-centos ~]# yum install mysql
  2. [root@VM-0-3-centos ~]# yum install mysql-server
  3. [root@VM-0-3-centos ~]# yum install mysql-devel

安装mysql和mysql-devel都成功,但是安装mysql-server失败,如下:

  1. [root@VM-0-3-centos ~]# yum install mysql-server Loaded plugins: fastestmirror Loading mirror speeds from cached hostfile * base: mirrors.sina.cn * extras: mirrors.sina.cn * updates: mirrors.sina.cn No package mysql-server available. Error: Nothing to do

因为CentOS 7 版本将MySQL数据库软件从默认的程序列表中移除,用mariadb代替了。
解决方法:

  1. [root@VM-0-3-centos ~]# wget http://dev.mysql.com/get/mysql-community-release-el7-5.noarch.rpm
  2. [root@VM-0-3-centos ~]# rpm -ivh mysql-community-release-el7-5.noarch.rpm
  3. [root@VM-0-3-centos ~]# yum install mysql-community-server

安装成功后重启MySQL服务

  1. [root@VM-0-3-centos ~]# service mysqld restart

首次安装mysql,root账户没有密码

  1. [root@VM-0-3-centos ~]# mysql -u root Welcome to the MySQL monitor.
  2. mysql>
  3. # 设置密码,本例已'password'作为密码,管理员修改设置自己的密码
  4. mysql> set password for 'root'@'localhost' =password('password');
  5. Query OK, 0 rows affected (0.00 sec) mysql>

centos 8 更改密码

  1. ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY '123456';

不需要重启MySQL即可生效

带密码模式登录

  1. mysql -u root -p

三、MySQL环境配置


1. 编码设置

mysql配置文件为/etc/my.cnf
在最后加上编码配置

  1. [mysql] default-character-set =utf8

这里的字符编码必须和/usr/share/mysql/charsets/Index.xml中一致

  1. <charset name="utf8"> <family>Unicode</family> <description>UTF-8 Unicode</description> <alias>utf-8</alias> <collation name="utf8_general_ci" id="33"> <flag>primary</flag> <flag>compiled</flag> </collation> <collation name="utf8_bin" id="83"> <flag>binary</flag> <flag>compiled</flag> </collation> </charset>

2. 远程连接设置


把所有数据库的所有表的所有权限赋值给位于所有IP地址的root用户

  1. mysql> grant all privileges on *.* to root@'%'identified by 'password';

如果是新用户而不是root,则要先新建用户

  1. mysql>create user 'username'@'%' identified by 'password';

设置完成有必要用下面指令刷新

  1. mysql>flush privileges;

设置完成后就可以远程连接了

参考:
1.https://blog.csdn.net/chuan403082010/article/details/84435533 sudo: apt-get: command not found
2.https://www.cnblogs.com/chenzibai/p/15835846.html centos mysql安装报错:The GPG keys listed for the “MySQL 8.0 Community Server” repository are already installed but they are not correct for this package.
3.https://www.jianshu.com/p/0bd7d22b489d centos7安装配置MySQL
4.https://zhuanlan.zhihu.com/p/303145027 linux vi vim文本编辑使用

code-server ftp mysql java需要重装