安装目录
安装在/usr/local目录,正常安装在home目录
# cd /usr/local
下载并安装MySQL官方的 Yum Repository
# 下载rpm
wget -i -c http://dev.mysql.com/get/mysql57-community-release-el7-10.noarch.rpm
# 安装
yum -y install mysql57-community-release-el7-10.noarch.rpm
# 安装 mysql-community-server
yum -y install mysql-community-server
这步可能会花些时间,安装完成后就会覆盖掉之前的mariadb,具体多久根据个人网速决定。
MySQL数据库设置
(1)首先启动MySQL
systemctl start mysqld.service
(2)查看MySQL运行状态,运行状态如图:
systemctl status mysqld.service
(3)在日志文件中找出密码:
grep “password” /var/log/mysqld.log
[root@localhost local]# grep "password" /var/log/mysqld.log
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。
如需修改密码复杂度参考如下命令:
set global validate_password.policy=LOW;
set global validate_password.length=6;
开启mysql的远程访问
mysql> grant all privileges on . to ‘root’@’%’ identified by ‘Wdq@123456’ with grant option;
mysql> flush privileges;
执行以下命令开启远程访问限制(注意:下面命令开启的IP是 192.168.19.128,如要开启所有的,用%代替IP):
mysql5.7.xxx
mysql> grant all privileges on *.* to 'root'@'192.168.0.1' identified by 'password' with grant option;
mysql> flush privileges;
mysql8.x.xx
创建用户:
mysql>create user 'root'@'%' identified by 'your password for root';
开启权限:
mysql>grant all on *.* to 'root'@'%';
验证:telnet 192.168.1.107(远程ip) 3306 或 mysql -u root -h 192.168.146.100 -p
如果远程连接的时候报plugin caching_sha2_password could not be loaded这个错误,可以在mysql主机上尝试修改密码加密插件:
mysql> alter user 'root'@'%' identified with mysql_native_password by '123456';
mysql> flush privileges;
注意
'root'@'%' %表示允许任意远程地方连接mysql
'root'@'192.168.146.100' 表示允许192.168.146.100这个地址远程连接mysql
password--是你设置你的mysql远程登录密码。
4 、开启防火墙端口,CentOS为firewalld添加开放端口3306,具体是什么参考如下:
https://i-beta.cnblogs.com/posts?cateId=1653053
5 、更改mysql的语言
首先重新登录mysql,然后输入status: