Linux CentOS7.9下安装MySQL5.7

卸载系统自带的mariadb

[root@10 ~]# yum remove mariadb-libs.x86_64

下载MySQL5.7的源

[root@10 ~]# wget https://repo.mysql.com/mysql57-community-release-el7-8.noarch.rpm

安装MySQL5.7的源

[root@10 ~]# yum localinstall mysql57-community-release-el7-8.noarch.rpm

下载MySQL服务

[root@10 ~]# yum install mysql-community-server -y

启动MySQL

[root@10 ~]# service mysqld  start

查看初始密码:

[root@10 ~]# cat /var/log/mysqld.log | grep 'password'                                                         
2022-01-16T04:10:43.404395Z 1 [Note] A temporary password is generated for root@localhost: THePjAZ:T21(

登陆MySQL

[root@10 ~]# mysql -uroot -p
Enter password: THePjAZ:T21(

修改MySQL密码:

mysql> SET PASSWORD = PASSWORD('123456');
ERROR 1819 (HY000): Your password does not satisfy the current policy requirements

提示当前设置密码不符合规范,用大写字母+数字+特殊字符混合一个密码即可

如果只想设置简单密码需要修改两个全局参数:

mysql> SET PASSWORD = PASSWORD('123456');
ERROR 1819 (HY000): Your password does not satisfy the current policy requirements
mysql> set global validate_password_policy=0;
Query OK, 0 rows affected (0.00 sec)

mysql> set global validate_password_length=1;
Query OK, 0 rows affected (0.00 sec)

mysql> SET PASSWORD = PASSWORD('123456');
Query OK, 0 rows affected, 1 warning (0.00 sec)

设置root可以远程连接

mysql> update  mysql.`user` set Host = '%' where User = 'root' and Host = 'localhost';
Query OK, 1 row affected (0.00 sec)
Rows matched: 1  Changed: 1  Warnings: 0

mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)

重启服务

sudo service mysqld restart

关闭防火墙

sudo service firewalld stop

你可能感兴趣的:(MySQL,Linux,linux,mysql,centos)