安装mysql5.7
环境: CentOS7
mysql源选择本地源:
[root@master ~]# ll win-share/mysql/57/ 总用量 207346 -rwxrwxrwx. 1 root root 26468960 2月 28 22:17 mysql-community-client-5.7.33-1.el7.x86_64.rpm -rwxrwxrwx. 1 root root 315280 12月 11 13:20 mysql-community-common-5.7.33-1.el7.x86_64.rpm -rwxrwxrwx. 1 root root 2458780 12月 11 13:21 mysql-community-libs-5.7.33-1.el7.x86_64.rpm -rwxrwxrwx. 1 root root 1260364 12月 11 13:21 mysql-community-libs-compat-5.7.33-1.el7.x86_64.rpm -rwxrwxrwx. 1 root root 181817592 2月 26 16:45 mysql-community-server-5.7.33-1.el7.x86_64.rpm drwxrwxrwx. 1 root root 0 3月 2 10:36 repodata
安装:
[root@master ~]# yum install mysql-community-server
从log日志里查看mysql的登录密码: ?O:Askd)s9tu就是系统生成的密码
[root@master ~]# grep "temporary password is generated" /var/log/mysqld.log 2021-03-09T23:36:31.157066Z 1 [Note] A temporary password is generated for root@localhost: ?O:Askd)s9tu
登录:因密码中有特殊字符所以要在-p后加“”(双引号)把密码括起来。
[root@master ~]# mysql -uroot -p"?O:Askd)s9tu" mysql: [Warning] Using a password on the command line interface can be insecure. Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 4 Server version: 5.7.33 Copyright (c) 2000, 2021, Oracle and/or its affiliates. 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>
跳过密码验证:在my.cnf的[mysqld]项里加入skip-grant-tables,并重启mysql生效
[root@CentOS7 ~]# vi + /etc/my.cnf [mysqld] skip-grant-tables
修改密码强度限制:(默认8位、大小写字母、特殊符号、数字)
注意:因为是实验环境密码强度可以降低,如果是生产环境要注意安全。
先修改默认密码:否则什么都不会让你操作
mysql> ALTER USER 'root'@'localhost' IDENTIFIED BY '?O:Askd)s9tu1'; Query OK, 0 rows affected (0.00 sec)
查看密码规则:
mysql> SHOW VARIABLES LIKE 'validate_password%'; +--------------------------------------+--------+ | Variable_name | Value | +--------------------------------------+--------+ | validate_password_check_user_name | OFF | | 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降低密码强度等级,
注意:重启数据库此项设置失效,将被还原成默认
mysql> set global validate_password_policy=LOW; Query OK, 0 rows affected (0.00 sec)
临时,密码长度设为6 默认8
注意:重启数据库此项设置失效,将被还原成默认
mysql> set global validate_password_length=6; Query OK, 0 rows affected (0.01 sec)
永久,不需要密码策略,在/etc/my.cnf文件中添加如下配置,禁用即可
validate_password = off
永久,/etc/my.cnf文件中添加
[root@CentOS7 ~]# vi + /etc/my.cnf [mysqld] validate_password_policy=0 #0(LOW),1(MEDIUM),2(STRONG)
永久,在/et/my.cnf文件中添加。
注意:如果设置validate_password = off ,validate_password_length 项会失效。
[root@CentOS7 ~]# vi + /etc/my.cnf [mysqld] validate_password_length=6
设置root密码为123456
mysql> ALTER USER 'root'@'localhost' IDENTIFIED BY '123456'; Query OK, 0 rows affected (0.00 sec)
查看数据库中的用户授权访问列表:
命令"use mysql"进入到mysql数据库中,再使用语句"select host, user from user;"查询登录用户的授权列表 ,显示root用户只能从本能登录.
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 from user; +---------------------+---------------+ | host | user | +---------------------+---------------+ | localhost | mysql.session | | localhost | mysql.sys | | localhost | root | +---------------------+---------------+
授权用户远程登录
注意:密码12345强度根据你mysql系统设置来设定,否则可能失败.
1、授权root用户可以从10.10.1.35登录MySQL数据库,如下所示: mysql> GRANT ALL PRIVILEGES ON *.* TO 'root'@'10.10.1.35' IDENTIFIED BY '123456' WITH GRANT OPTION; 2、授权root用户可以从任意电脑登录MySQL数据库。如下所示: mysql> GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY '123456' WITH GRANT OPTION;
保存授权名单
mysql> flush privileges;
删除授权地址和用户
mysql> delete from user where host = 'host地址' and user = '登录名';
测试数据库是否能正常操作:
mysql>use test; Database changed mysql>create table abc.t0417(id int,name varchar(20)); Query OK, 0 rows affected (0.08 sec) mysql>use test; Database changed mysql>insert into abc.t0417 values(1,'a'); Query OK, 1 row affected (0.02 sec) mysql>select * from t0417; +------+------+ | id | name | +------+------+ | 1 | a | +------+------+ 1 rows in set (0.01 sec)
===========================================================================================================================
错误:
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES)
原因:重启Mysql前没有退出mysql客户端命令行.
解决方法:quit(exit)退出命令行,重新进入.
参考:
http://blog.csdn.net/wohiusdashi/article/details/89358071
http://zhuanlan.zhihu.com/p/200909519
http://jingyan.baidu.com/article/f7ff0bfcb914916e26bb13ac.html
http://moneyslow.com/mysql-5-7-关闭密码策略设置validate_password.html
t0417