时间:2021-07-01 10:21:17 帮助过:2人阅读
1、下载:
https://dev.mysql.com/downloads/mysql/
选择MySQL Community Server 5.7.20--> Red Hat Enterprise Linux/Oracle Linux--> RPM Bundle -->mysql-5.7.20-1.el7.x86_64.rpm-bundle.tar
2、上传所需要的rpm包、安装
# yum remove mariadb-libs -y
# ll *.rpm
-rw-r--r--. 1 root root 25090196 Nov 2 16:12 mysql-community-client-5.7.20-1.el7.x86_64.rpm
-rw-r--r--. 1 root root 278300 Nov 2 16:12 mysql-community-common-5.7.20-1.el7.x86_64.rpm
-rw-r--r--. 1 root root 2238604 Nov 2 16:12 mysql-community-libs-5.7.20-1.el7.x86_64.rpm
-rw-r--r--. 1 root root 171597916 Nov 2 16:12 mysql-community-server-5.7.20-1.el7.x86_64.rpm
3、安装并启动
# rpm -ivh mysql-community-*.rpm #安装完之后创建一个/etc/my.cnf文件
# systemctl start mysqld 启动
4、获取密码登陆修改密码
获取密码,对于MySQL 5.7.6和更高的版本来说,初始的随机root密码是被写入错误日志的。对于MySQL5.7.4和5.7.5版本来说,密码是被写入以HOME环境变量命名的目录中的.mysql_secret文件中的。
从MySQL 5.7.6版本起数据目录和root账户由mysqld --initialize来初始化,5.7.6以前的版本由mysql_install_db来初始化
初始化方法:
shell> bin/mysqld --initialize --user=mysql
shell> bin/mysqld --initialize-insecure --user=mysql mysql -u root --skip-password
# grep ‘temporary password‘ /var/log/mysqld.log
xxx-xx-02T0x:19:07.885209Z 1 [Note] A temporary password is generated for root@localhost: %kr9>U3dWKK
登陆并修改密码
# mysql -uroot -p
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 ‘xxxx‘;
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)
mysql> exit
5、将MySQL服务开机启动
# systemctl enable mysqld
补充:
一、MySQL 5.7 修改密码的方法
1、update mysql.user set authentication_string=password(‘xxxx‘) where user=‘root‘ and Host = ‘localhost‘;
2、alter user ‘root‘@‘localhost‘ identified by ‘xxxx‘;
3、set password for ‘root‘@‘localhost‘=password(‘xxxx‘);
4、grant all on *.* to test@‘%‘ identified by [password] ‘xxxx‘;
5、mysqladmin -u root -h localhost password ‘xxxx‘ -p
二、随便修改密码,不受密码的限制
mysql> set global validate_password_policy=0;
mysql>set global validate_password_length=0;
三、备份与恢复
mysqldump -uroot -p -single-transaction -R --default-character-set=utf8 --triggers --events --hex-blob --flush-logs --master-data=2 -A >/xxx/backup/xxxx.sql
mysql < xxxx.sql
CHANGE MASTER TO MASTER_HOST=‘xxx.xxx.xxx.xxx‘,MASTER_USER=‘xxx‘,MASTER_PASSWORD=‘xxxxx‘,MASTER_PORT=xxxx,MASTER_LOG_FILE=‘xxxxxx‘,MASTER_LOG_POS=xxxx,MASTER_CONNECT_RETRY=10;
四、MySQL下的几个常用命令:
mysql> ?
mysql> \u mysql
mysql> \! ls
mysql> \s
mysql> \q
Bye
五、redhat 7查看服务列表
# systemctl list-unit-files
六、技巧
1、修改用户密码之后要验证,验证之前不要退出当前session
2、不要随便去vi 一个文件,用cat |less的方式,这样更加的安全
本文出自 “小鱼的博客” 博客,谢绝转载!
linux 7.4 采用RPM安装mysql-5.7.20
标签:ja