1.安装mysql客户端,用于连接mysql服务。
yum install mysql
2.复制mysql的rpm下载地址(官网的下载地址:https://dev.mysql.com/downloads/repo/yum/,需要登入)
3.centos7下载mysql的rpm
wget https://dev.mysql.com/get/mysql80-community-release-el7-3.noarch.rpm
4.安装mysql的rpm
rpm -ivh mysql80-community-release-el7-3.noarch.rpm
5.安装mysql服务
yum install mysql-server
6.修改/etc/my.cnf 文件,不用密码登入
vi /etc/my.cnf
#添加
skip-grant-tables
7.启动并连接mysql服务
#启动
systemctl start mysqld
#连接
mysql -uroot -p #回车 回车
8.修改密码
#刷新权限
mysql> flush privileges;
Query OK, 0 rows affected (0.01 sec)
#查看验证
mysql> show variables like "%validate%";
+--------------------------------------+--------+
| 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)
#修改密码最短长度6
mysql> set global validate_password.length=6;
Query OK, 0 rows affected (0.00 sec)
#修改密码简单规则
mysql> set global validate_password.policy=0;
Query OK, 0 rows affected (0.00 sec)
#修改密码
alter user 'root'@'localhost' identified with mysql_native_password by '123456';
#刷新权限
mysql> flush privileges;
Query OK, 0 rows affected (0.01 sec)
9.允许远程访问
#使用mysql数据库
mysql> use mysql
Database changed
#查看用户允许访问的host
mysql> select host,user from user;
+-----------+------------------+
| host | user |
+-----------+------------------+
| localhost | mysql.infoschema |
| localhost | mysql.session |
| localhost | mysql.sys |
| localhost | root |
+-----------+------------------+
4 rows in set (0.00 sec)
#修改root的host
mysql> update user set host='%' where user='root';
Query OK, 1 row affected (0.01 sec)
Rows matched: 1 Changed: 1 Warnings: 0
#刷新权限
mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)
10.注释/etc/my.cnf 的skip-grant-tables ,重新启动mysql服务
vi etc/my.cnf
#skip-grant-tables
#启动mysql服务
[root@VM-0-17-centos ~]# systemctl restart mysqld
[root@VM-0-17-centos ~]#
11.卸载mysql服务
#删除安装
#rpm -qa |grep -i mysql | xargs yum remove -y
#删除有关文件
#find / -name mysql | xargs rm -rf
#删除/etc/my.cnf
rm -rf /etc/my.cnf
#删除log
rm -rf /var/log/mysqld.log