[root@i3467544tdsxfrZ ~]# rpm -ivh mysql-community-server-5.7.22-1.el7.x86_64.rpm warning: mysql-community-server-5.7.22-1.el7.x86_64.rpm: Header V3 DSA/SHA1 Signature, key ID 5072e1f5: NOKEY error: Failed dependencies: libaio.so.1()(64bit) is needed by mysql-community-server-5.7.22-1.el7.x86_64 libaio.so.1(LIBAIO_0.1)(64bit) is needed by mysql-community-server-5.7.22-1.el7.x86_64 libaio.so.1(LIBAIO_0.4)(64bit) is needed by mysql-community-server-5.7.22-1.el7.x86_64
[root@nfs_client tools]# grep 'temporary password' /var/log/mysqld.log # 在/var/log/mysqld.log文件中搜索字段‘temporary password’ 2018-07-18T06:02:23.579753Z 1 [Note] A temporary password is generated for root@localhost: n(jPp4l-C33#
n(jPp4l-C33#即为登录密码。使用这个随机密码登录进去,然后修改密码,使用命令:
mysql -uroot -p
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
[root@nfs_client tools]# mysql -uroot -p Enter password: # 在这里输入密码 Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 2 Server version: 5.7.22 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> quit # 输入quit 或 exit 都能退出mysql Bye
执行下面的命令修改MySql root密码
在5.6后,mysql内置密码增强机制,低强度密码会报错:
1 2 3 4 5
mysql> alter user root@localhost identified by 'sdbrk'; ERROR 1819 (HY000): Your password does not satisfy the current policy requirements 或 mysql>set password for root@localhost=password('sdbrk'); ERROR 1819 (HY000): Your password does not satisfy the current policy requirements
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 user,host from user; +---------------+-----------+ | user | host | +---------------+-----------+ | root | % | | mysql.session | localhost | | mysql.sys | localhost | | root | localhost | +---------------+-----------+ 4 rows in set (0.00 sec) mysql> show grants; +---------------------------------------------------------------------+ | Grants for root@localhost | +---------------------------------------------------------------------+ | GRANT ALL PRIVILEGES ON *.* TO 'root'@'localhost' WITH GRANT OPTION | | GRANT PROXY ON ''@'' TO 'root'@'localhost' WITH GRANT OPTION | +---------------------------------------------------------------------+ 2 rows in set (0.00 sec)
step3: 授予root用户远程访问权限:
1 2
mysql> grant all privileges on *.* to root@'%' identified by '9527'; Query OK, 0 rows affected, 1 warning (0.05 sec)
[root@localhost ~]# mysql -h192.168.0.241 -uroot -p Enter password: Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 20 Server version: 5.7.22 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> show grants; +-------------------------------------------+ | Grants for root@% | +-------------------------------------------+ | GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' | +-------------------------------------------+ 1 row in set (0.01 sec) mysql>
mysql中可以给一个用户授予如select,insert,update,delete等其中的一个或者多个权限,主要使用grant命令,用法格式为: grant 权限 on 数据库对象 to 用户 一、grant 普通数据用户,查询、插入、更新、删除 数据库中所有表数据的权利。 grant select on testdb.* to common_user@’%’ grant insert on testdb.* to common_user@’%’ grant update on testdb.* to common_user@’%’ grant delete on testdb.* to common_user@’%’ 或者,用一条 MySQL 命令来替代: grant select, insert, update, delete on testdb.* to common_user@’%’