Redhat7下安装mysql

1、下载安装包
https://dev.mysql.com/downloads/mysql/5.5.html?os=31&version=5.1

mysql-5.7.18-1.el7.x86_64.rpm-bundle.tar

2、解压安装包
tar -xvf mysql-5.7.18-1.el7.x86_64.rpm-bundle.tar

3、移除已经安装的早期版本
执行删除命令
yum remove mysql-libs

4、安装顺序
rpm -ivh mysql-community-common-5.7.18-1.el7.x86_64.rpm
rpm -ivh mysql-community-libs-5.7.18-1.el7.x86_64.rpm
rpm -ivh mysql-community-client-5.7.18-1.el7.x86_64.rpm
rpm -ivh mysql-community-server-5.7.18-1.el7.x86_64.rpm
rpm -ivh mysql-community-devel-5.7.18-1.el7.x86_64.rpm

5、启动Mysql服务
service mysqld start

6、修改root密码
1)初始密码
grep 'temporary password' /var/log/mysqld.log
2019-01-31T09:00:55.852636Z 1 [Note] A temporary password is generated for root@localhost: :?lMRbHmn6.p

  1. 登录Mysql
    mysql -uroot -p:?lMRbHmn6.p

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 6
Server version: 5.7.18

Copyright (c) 2000, 2017, 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>

  1. 修改密码
    mysql> ALTER USER USER() IDENTIFIED BY '123456';
    ERROR 1819 (HY000): Your password does not satisfy the current policy requirements

  2. 修改validate_password_policy参数的值
    mysql> set global validate_password_policy=0;
    Query OK, 0 rows affected (0.00 sec)

  3. 修改为简单密码:
    mysql> ALTER USER USER() IDENTIFIED BY '12345678';
    Query OK, 0 rows affected (0.00 sec)

mysql>

  1. 查看当前密码长度限制
    mysql> select @@validate_password_length;
    +----------------------------+
    | @@validate_password_length |
    +----------------------------+
    | 8 |
    +----------------------------+
    1 row in set (0.00 sec)

7) 修改密码长度限制
mysql> set global validate_password_length=1;
Query OK, 0 rows affected (0.00 sec)

mysql> select @@validate_password_length;
+----------------------------+
| @@validate_password_length |
+----------------------------+
| 4 |
+----------------------------+
1 row in set (0.00 sec)

8)修改密码为123456

mysql> ALTER USER USER() IDENTIFIED BY '123456';
Query OK, 0 rows affected (0.00 sec)

7、授权远程登录

mysql> grant all privileges on . to 'root'@'%' identified by '123456' with grant option;
Query OK, 0 rows affected, 1 warning (0.00 sec)

mysql -uroot -proot -e "grant all privileges on . to 'root'@'%' identified with grant option;"

8、 验证
(python3.5.6) [root@promote software_packages]# mysql -h 192.168.1.188 -P 3306 -u root -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 8
Server version: 5.7.18 MySQL Community Server (GPL)

Copyright (c) 2000, 2017, 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>

8、执行mysql脚本

进入mysql控制台后,用source *.sql执行

9、root密码丢失或重置

service mysqld stop

mysqld --skip-grant-tables --user=root

mysql>update mysql.user set authentication_string=password('123456') where user='root';
mysql>flush privileges;
mysql>quit;

cd /var/lib/mysql

//查看归属用户,必须是mysql,不然会启动失败

©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

友情链接更多精彩内容