记录一下在Centos7(最小化安装模式,命令行模式,不带图形界面)下安装Mysql8的方式,这里采用最简单的Yum安装方式。
Mysql安装步骤
查看mysql yum仓库中mysql版本,使用如下命令
yum repolist all | grep mysql
检查一下yum仓库下是否有mysql。
yum list |grep mysql
发现没有mysql,需要在本地仓库配置一下Mysql源。
yum仓库下载MySQL:
sudo yum localinstall https://repo.mysql.com//mysql80-community-release-el7-1.noarch.rpm
这里的路径上官网找红帽的即可。
yum安装MySQL:
sudo yum install mysql-community-server
Dependency Updated:
postfix.x86_64 2:2.10.1-9.el7
Replaced:
mariadb-libs.x86_64 1:5.5.60-1.el7_5
Complete!
安装完成,从日志看替换了mariadb(Mysql完全开源版本)。
Mysql配置
启动MySQL:
systemctl start mysqld.service
查看MySQL运行状态:
systemctl status mysqld.service
看到active(running) 即为启动成功
查看初始化密码
grep “password” /var/log/mysqld.log
g>DgEdVRT5l2
进入数据库
MySQL -uroot -p刚才复制的密码
修改密码
alter user ‘root’@‘localhost’ identified by ‘!QAZ2wsx12312’;
密码必须复杂。必须有大小写字母数字和特殊字符不低于8位。
查看MySQL完整初始化密码规则
show variables like ‘validate_password%’;
mysql> show variables like 'validate_password%';
+--------------------------------------+--------+
| Variable_name | Value |
+--------------------------------------+--------+
| validate_password.check_user_name | ON |
| validate_password.dictionary_file | |
| validate_password.length | 8 |
| validate_password.mixed_case_count | 1 |
| validate_password.number_count | 1 |
| validate_password.policy | MEDIUM |
| validate_password.special_char_count | 1 |
+--------------------------------------+--------+
7 rows in set (0.01 sec)
配置访问
mysql -u root -p
mysql>use mysql;
mysql> select user,host from user;
+------------------+-----------+
| user | host |
+------------------+-----------+
| mysql.infoschema | localhost |
| mysql.session | localhost |
| mysql.sys | localhost |
| root | localhost |
+------------------+-----------+
4 rows in set (0.00 sec)
mysql> update user set host='%' where user='root';
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)
alter user 'root'@'%' identified by '!QAZ2wsx';
端口开发
[root@localhost ~]# firewall-cmd --zone=public --add-port=3306/tcp --permanent
success
[root@localhost ~]# firewall-cmd --reload
success
解决Navicat for MySQL 连接 Mysql 8.0.11 出现1251- Client does not support authentication protocol 错误
错误原因:
mysql8 之前的版本中加密规则是mysql_native_password,而在mysql8之后,加密规则是caching_sha2_password
解决方法:
把mysql用户登录密码加密规则还原成mysql_native_password.
具体步骤:
1.在cmd窗口进入sql
2.ALTER USER ‘root’@‘%’ IDENTIFIED WITH mysql_native_password BY ‘password’;
alter user ‘root’@’%’ identified WITH mysql_native_password by ‘!QAZ2wsx’;
#更新一下用户的密码
3.FLUSH PRIVILEGES; #刷新权限
版本
mysql> select version();
+-----------+
| version() |
+-----------+
| 8.0.21 |
+-----------+
1 row in set (0.00 sec)