mysql5.7版本yum安装---redhat7.0

本文详细介绍了在Linux环境下安装MySQL5.7的过程,包括从官网下载YUM包、安装依赖、启动服务、初始化数据库、修改管理员密码及设置开机自启等关键步骤。

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

 

转载于:https://www.cnblogs.com/lczz/p/10084015.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值