快速搭建MySQL 数据库
一、安装
0)把本地或网络yum 源开启
1)下载mysql80-community-release-el7-1.noarch.rpm
wget https://repo.mysql.com//mysql80-community-release-el7-1.noarch.rpm
2)安装
rpm -ivh mysql80-community-release-el7-1.noarch.rpm
3)修 MySQL 的repo源,让MySQL8.0开启
vim /etc/yum.repos.d/mysql-community.repo
修改[mysql80-community] enabled=1,原来为enabled=1则不用修改,保存并退出。
4)安装 mysql-server
yum install mysql-server
提示都选yes
5)改 MySQL 访问权限
chown -R root:root /var/lib/mysql
6)重启 MySQL 服务
service mysqld restart
MySQL8.0 安装完成!
二、重置密码
1)查看默认密码
grep 'temporary password' /var/log/mysqld.log
[root@localhost test_led]# grep 'temporary password' /var/log/mysqld.log
2018-08-07T03:04:52.899706Z 5 [Note] [MY-010454] [Server] A temporary password is generated for root@localhost: BrOlVTAUW6,/
BrOlVTAUW6为密码,不方便记忆,需重置
2)配置文件 MySQL ,实现免密码登录
vim /etc/my.cnf
在行:pid-file=/var/run/mysqld/mysqld.pid,添加 如下
skip-grant-tables
保存,重启
service mysqld restart
3)免密码登录
mysql -u root -p
按回车后进入登录完成
弹出如下
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 7
Server version: 8.0.12 MySQL Community Server - GPL
Copyright (c) 2000, 2018, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql>
4)选择 mysql 数据库
输入 use mysql;
弹出如下
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A
Database changed
mysql> select host, user, authentication_string, plugin from user;
+-----------+------------------+------------------------------------------------------------------------+-----------------------+
| host | user | authentication_string | plugin |
+-----------+------------------+------------------------------------------------------------------------+-----------------------+
| localhost | mysql.infoschema | $A$005$THISISACOMBINATIONOFINVALIDSALTANDPASSWORDTHATMUSTNEVERBRBEUSED | caching_sha2_password |
| localhost | mysql.session | $A$005$THISISACOMBINATIONOFINVALIDSALTANDPASSWORDTHATMUSTNEVERBRBEUSED | caching_sha2_password |
| localhost | mysql.sys | $A$005$THISISACOMBINATIONOFINVALIDSALTANDPASSWORDTHATMUSTNEVERBRBEUSED | caching_sha2_password |
| localhost | root | $A$005$H%@nE
`py\CVEJ3oZxLxwMniNjVB8anG5ujE72wZG3P3WBjPdjFsO9B0 | caching_sha2_password |
+-----------+------------------+------------------------------------------------------------------------+-----------------------+
4 rows in set (0.00 sec)
5)将默认的 root 密码置空
update user set authentication_string='' where user='root';
6)退出 mysql
输入quit
mysql> quit
7)删除 /etc/my.cnf 文件最后的 skip-grant-tables并重启
vim /etc/my.cnf
dd skip-grant-tables 保存
service mysqld restart
8)重新登录到MySQL
mysql -u root -p
按回车直接进入
9)使用 ALTER 修改 root 用户密码
mysql> ALTER user 'root'@'localhost' IDENTIFIED BY 'qQ1i2px@';
qQ1i2px@为密码;
成功后提示Query OK, 0 rows affected (0.12 sec),之后可以使用此密码登录,搞定!
ps:密码要复杂才能设置成功,否则不成功,最好设置成大写字母、数字、符号的组合。提示不成功时如下
mysql> ALTER user 'root'@'localhost' IDENTIFIED BY 'admin123';
ERROR 1819 (HY000): Your password does not satisfy the current policy requirements
mysql> ALTER user 'root'@'localhost' IDENTIFIED BY 'admin123@';
ERROR 1819 (HY000): Your password does not satisfy the current policy requirements
mysql> ALTER user 'root'@'localhost' IDENTIFIED BY 'Admin123';
ERROR 1819 (HY000): Your password does not satisfy the current policy requirements
mysql> ALTER user 'root'@'localhost' IDENTIFIED BY 'admin190';
ERROR 1819 (HY000): Your password does not satisfy the current policy requirements
mysql> ALTER user 'root'@'localhost' IDENTIFIED BY 'Xpf123@';
ERROR 1819 (HY000): Your password does not satisfy the current policy requirements