1.环境
1.1 Windwos
1.2 Linux
直接使用yum命令进行安装。
sudo yum install mysql
sudo yum install mysql-server
2.初始化
2.1 linux 安装完成后不记得密码
1、使用yum安装mysql后
2、初始密码在/var/log/mysqld.log这个文件里
3、输入命令:grep 'temporary password' /var/log/mysqld.log,可以直接获取密码。
[admin@localhost 桌面]$ sudo grep 'temporary password' /var/log/mysqld.log
[sudo] admin 的密码:
2021-07-01T12:41:06.341887Z 6 [Note] [MY-010454] [Server] A temporary password is generated for root@localhost: r,%uWwa_t5rU
2.2 重设密码
安装完成后,初次登录会提示
ERROR 1820 (HY000): You must reset your password using ALTER USER statement before executing this statement.
按照提示,修改密码
alter user user() identified by "123456";
提示报错,密码太简单
ERROR 1819 (HY000): Your password does not satisfy the current policy requirements
提示密码太简单,写个复杂的就好,如果介意的话,可以搜索这个报错,网上有降低密码等级的方案,提供个地址,懒得找的看看这个
https://blog.youkuaiyun.com/qq_39344689/article/details/89674079
2.3 开放用户权限等
查看当当前用户信息
mysql> select host, user, plugin, authentication_string from user;
+-----------+------------------+-----------------------+------------------------------------------------------------------------+
| host | user | plugin | authentication_string |
+-----------+------------------+-----------------------+------------------------------------------------------------------------+
| localhost | mysql.infoschema | caching_sha2_password | $A$005$THISISACOMBINATIONOFINVALIDSALTANDPASSWORDTHATMUSTNEVERBRBEUSED |
| localhost | mysql.session | caching_sha2_password | $A$005$THISISACOMBINATIONOFINVALIDSALTANDPASSWORDTHATMUSTNEVERBRBEUSED |
| localhost | mysql.sys | caching_sha2_password | $A$005$THISISACOMBINATIONOFINVALIDSALTANDPASSWORDTHATMUSTNEVERBRBEUSED |
| localhost | root | caching_sha2_password | $A$005$z!%7o7`+}b
?%qK8&qJdY9peRaWEurcGm3MxC1japb79lg7O.qkWliWPrVH3 |
+-----------+------------------+-----------------------+------------------------------------------------------------------------+
4 rows in set (0.00 sec)
1.改为 native_password
alter user 'root'@'localhost' identified with mysql_native_password by 'XXXXX';
flush privileges;
2.允许远程访问
update user set host="%" where user='root';
flush privileges;