安装教程
# 获取MySQL8.0源
wget https://dev.mysql.com/get/mysql80-community-release-el7-2.noarch.rpm
# 安装源
rpm -ivh mysql80-community-release-el7-2.noarch.rpm
# 安装MySQL
yum -y install mysql-community-server --nogpgcheck
# 启动MySQL并设置开机自启
systemctl start mysqld
systemctl enable mysqld
# 查看初始密码,MySQL启动成功才会有日志生成,才能查看到密码
grep 'password' /var/log/mysqld.log
# 使用查看到的密码登录MySQL
mysql -uroot -p
mysql> show databases;
ERROR 1820 (HY000): You must reset your password using ALTER USER statement before executing this statement.
mysql> ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY '123456';
ERROR 1819 (HY000): Your password does not satisfy the current policy requirements
mysql> ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY '123qweQWE!@#';
Query OK, 0 rows affected (0.00 sec)
然后修改
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)
set global validate_password.policy=LOW;
set global validate_password.length=6;
mysql> ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY '123456';
Query OK, 0 rows affected (0.01 sec)
配置远程连接,创建一个远程连接用户
mysql> create user 'root'@'%' identified by '123456';
Query OK, 0 rows affected (0.01 sec)
这样的话,就可以在远程登录了,但是还不能去进行建库操作,如下:
mysql> create database test;
ERROR 1044 (42000): Access denied for user 'test'@'%' to database 'test'
还得需要去赋权,
mysql> grant all privileges on *.* to 'root'@'%' with grant option;
Query OK, 0 rows affected (0.00 sec)