安装目录

安装在/usr/local目录,正常安装在home目录

  1. # cd /usr/local

下载并安装MySQL官方的 Yum Repository

  1. # 下载rpm
  2. wget -i -c http://dev.mysql.com/get/mysql57-community-release-el7-10.noarch.rpm
  3. # 安装
  4. yum -y install mysql57-community-release-el7-10.noarch.rpm
  5. # 安装 mysql-community-server
  6. yum -y install mysql-community-server
  7. 这步可能会花些时间,安装完成后就会覆盖掉之前的mariadb,具体多久根据个人网速决定。

MySQL数据库设置

(1)首先启动MySQL

  1. systemctl start mysqld.service

(2)查看MySQL运行状态,运行状态如图:

  1. systemctl status mysqld.service

(3)在日志文件中找出密码:
grep “password” /var/log/mysqld.log

  1. [root@localhost local]# grep "password" /var/log/mysqld.log
  2. 2021-08-07T04:08:27.178096Z 1 [Note] A temporary password is generated for root@localhost: oJ,#&omfp2EF

(4)如下命令登录数据库:
mysql -uroot -p

(5)此时不能做任何事情,因为MySQL默认必须修改密码之后才能操作数据库,如下命令修改密码:
mysql> ALTER USER ‘root’@’localhost’ IDENTIFIED BY ‘123456’;

报错如下

ERROR 1819 (HY000): Your password does not satisfy the current policy requirements

原因:(123456密码太弱)
其中‘123456’替换成你要设置的密码,注意:密码设置必须要大小写字母数字和特殊符号(,/‘;:等),不然不能配置成功,Wdq@123456。

  1. 如需修改密码复杂度参考如下命令:
  2. set global validate_password.policy=LOW;
  3. set global validate_password.length=6;

开启mysql的远程访问

mysql> grant all privileges on . to ‘root’@’%’ identified by ‘Wdq@123456’ with grant option;

mysql> flush privileges;

  1. 执行以下命令开启远程访问限制(注意:下面命令开启的IP 192.168.19.128,如要开启所有的,用%代替IP):
  2. mysql5.7.xxx
  3. mysql> grant all privileges on *.* to 'root'@'192.168.0.1' identified by 'password' with grant option;
  4. mysql> flush privileges;
  5. mysql8.x.xx
  6. 创建用户:
  7. mysql>create user 'root'@'%' identified by 'your password for root';
  8. 开启权限:
  9. mysql>grant all on *.* to 'root'@'%';
  10. 验证:telnet 192.168.1.107(远程ip) 3306 mysql -u root -h 192.168.146.100 -p
  11. 如果远程连接的时候报plugin caching_sha2_password could not be loaded这个错误,可以在mysql主机上尝试修改密码加密插件:
  12. mysql> alter user 'root'@'%' identified with mysql_native_password by '123456';
  13. mysql> flush privileges
  14. 注意
  15. 'root'@'%' %表示允许任意远程地方连接mysql
  16. 'root'@'192.168.146.100' 表示允许192.168.146.100这个地址远程连接mysql
  17. password--是你设置你的mysql远程登录密码。
  18. 4 、开启防火墙端口,CentOSfirewalld添加开放端口3306,具体是什么参考如下:
  19.     https://i-beta.cnblogs.com/posts?cateId=1653053
  20. 5 、更改mysql的语言
  21. 首先重新登录mysql,然后输入status