mysql数据库技巧

centos7.4 yum 安装mysql5.7

使用wget下载官方yum源的rpm包:
wget https://dev.mysql.com/get/mysql57-community-release-el7-11.noarch.rpm
安装rpm包:
rpm -ivh mysql57-community-release-el7-11.noarch.rpm
yum来安装mysql-server:
yum install -y mysql-server
启动mysqld服务:
systemctl start mysqld
查看是否成功启动:
ps aux|grep mysqld
设置mysqld服务开机自启动:
systemctl enable mysqld
使用初始密码登录
由于MySQL从5.7开始不允许首次安装后,使用空密码进行登录,系统会随机生成一个密码以供管理员首次登录使用,这个密码记录在/var/log/mysqld.log文件中,使用下面的命令可以查看此密码:
[root@bjlianyi wordpress]# cat /var/log/mysqld.log|grep ‘A temporary password’
2018-06-29T15:08:12.364210Z 1 [Note] A temporary password is generated for root@localhost: f<%qrUl/f0lG
[root@bjlianyi wordpress]# mysql
ERROR 1045 (28000): Access denied for user ‘root’@’localhost’ (using password: NO)
[root@bjlianyi wordpress]# mysql -uroot -p
Enter password: 
ERROR 1045 (28000): Access denied for user ‘root’@’localhost’ (using password: NO)
[root@bjlianyi wordpress]# mysql -uroot -p
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 4
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> show databases;
ERROR 1820 (HY000): You must reset your password using ALTER USER statement before executing this statement.

来个密码:
mysql> alter user root@’localhost’ identified by ‘NDH7euHW82yrWH’;
ERROR 1819 (HY000): Your password does not satisfy the current policy requirements
太简单了,没让过,来个复杂的:
mysql> alter user ‘root’@’localhost’ identified by ‘Ne%uHW82y&rWH’;
Query OK, 0 rows affected (0.00 sec)

mysql> show databases;
+——————–+
| Database           |
+——————–+
| information_schema |
| mysql              |
| performance_schema |
| sys                |
+——————–+
4 rows in set (0.00 sec)