mysql5.7版本yum安装---redhat7.0
1.官网下载yum包
[root@test01 test]# wget http://dev.mysql.com/get/mysql57-community-release-el7-10.noarch.rpm ./
2.安装mysql依赖包
[root@test01 test]# ls mysql57-community-release-el7-10.noarch.rpm [root@test01 test]# yum install -y mysql57-community-release-el7-10.noarch.rpm
3.安装mysql
[root@test01 test]# yum install -y mysql-community-server.x86_64
4.启动mysql服务
[root@test01 test]# systemctl start mysqld.service
mysql服务器初次启动时,会有一个初始化过程,给服务器一个空的数据目录(data)
1.服务器被初始化
2.在数据目录中生成SSL证书和密钥文件
3.安装validate_password插件并启动
4.创建超级用户“root”@“localhost”,密码被设置并且存储在错误日志文件中
5.在错误日志中找出密码并进入服务器修改密码
[root@test01 test]# grep 'temporary password' /var/log/mysqld.log
找出密码后直接登入服务器,修改密码
[root@test01 test]# mysql -uroot -p
ALTER USER 'root'@'localhost' IDENTIFIED BY 'redhat';
密码若太过简单会报错
也可以运行mysql_secure_installation程序来修改密码,不过官网上建议5.7及以上版本不建议运行这个程序,因为这个程序的功能已经被yum存储仓库安装完成
mysql_secure_installation — Improve MySQL Installation Security for details. Do not run mysql_secure_installation after an installation of MySQL 5.7 or higher, as the function of the program has already been performed by the Yum repository installation.
还有一种方法是编辑mysql的配置文件 my.cnf 在 [mysqld]下添加一行skip-grant-tables,重启服务
[root@test01 test]# vim /etc/my.cnf [root@test01 test]# systemctl restart mysqld.service [root@test01 test]# mysql -uroot
mysql> use mysql ==>使用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> update user set password=PASSWORD('redhat') where user='root'; ==>修改user表的数据,修改用户root的密码 Query OK, 0 rows affected, 1 warning (0.11 sec) Rows matched: 4 Changed: 0 Warnings: 1 mysql> flush privileges; ==>刷新权限表 Query OK, 0 rows affected (0.07 sec)
退出数据库,在编辑配置文件my.cnf,删除新增的那一行
mysql> exit Bye [root@test01 test]# vim /etc/my.cnf [root@test01 test]# systemctl restart mysqld.service [root@test01 test]# mysql -uroot -predhat 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 2 Server version: 5.7.24 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>
可以正常登入了
6.设置开机自启
[root@test01 test]# systemctl enable mysqld.service