centos7安装MySQL教程

太阳渐渐往下落,它的脸涨得越来越红,红的像个大火球,把身边的云染成五颜六色。慢慢地它走到西山背后,把美丽的霞光留在遥远的天边。我们都看得目瞪口呆。我的心里在想:晚霞真美!

实测centos 7 中安装mysql-5.7版本数据库的详细过程,在安装mysql-5.7的时候,可以通过查看日志(/var/log/mysqld.log)提示的错误,进行一步步的调试安装。这样可以快速准确的解决各种问题,完成搭建。

官网下载地址:https://dev.mysql.com/downloads/mysql/5.7.html#downloads

一、安装MySQL

下载解压:

#下载软件包
wget -c https://dev.mysql.com/get/Downloads/MySQL-5.7/mysql-5.7.23-1.el7.x86_64.rpm-bundle.tar
#解压包
tar -xvf mysql-5.7.23-1.el7.x86_64.rpm-bundle.tar
#包
[root@zixuephp ~]# ls
mysql-5.7.23-1.el7.x86_64.rpm-bundle.tar                 
mysql-community-libs-5.7.23-1.el7.x86_64.rpm              
mysql-community-client-5.7.23-1.el7.x86_64.rpm           
mysql-community-libs-compat-5.7.23-1.el7.x86_64.rpm        
mysql-community-common-5.7.23-1.el7.x86_64.rpm           
mysql-community-minimal-debuginfo-5.7.23-1.el7.x86_64.rpm  
mysql-community-devel-5.7.23-1.el7.x86_64.rpm            
mysql-community-server-5.7.23-1.el7.x86_64.rpm             
mysql-community-embedded-5.7.23-1.el7.x86_64.rpm         
mysql-community-server-minimal-5.7.23-1.el7.x86_64.rpm     
mysql-community-embedded-compat-5.7.23-1.el7.x86_64.rpm  
mysql-community-test-5.7.23-1.el7.x86_64.rpm              
mysql-community-embedded-devel-5.7.23-1.el7.x86_64.rpm

依次安装MySQL rpm:

rpm -ivh mysql-community-server-5.7.23-1.el7.x86_64.rpm --force --nodeps
rpm -ivh mysql-community-libs-5.7.23-1.el7.x86_64.rpm --force --nodeps
rpm -ivh mysql-community-client-5.7.23-1.el7.x86_64.rpm --force --nodeps
rpm -ivh mysql-community-common-5.7.23-1.el7.x86_64.rpm --force --nodeps
rpm -ivh mysql-community-libs-compat-5.7.23-1.el7.x86_64.rpm --force --nodeps

二、启动MySQL

systemctl start mysqld
[root@zixuephp ~]# ps -aux|grep mysqld
mysql    25145  1.5  8.1 1119500 166632 ?      Sl   10:10   0:00 /usr/sbin/mysqld --daemonize --pid-file=/var/run/mysqld/mysqld.pid

*如果启动失败,则需要对配置文件进行配置(增加配置文件中不存在的下面的配置参数):

#编辑配置文件
vim /etc/my.cof
#配置文件内容
#数据库存放目录,如果不存在旧创建
datadir=/var/lib/mysql/data
#连接文件,如果不存在则创建,并设置mysql用户所有者和mysql组
socket=/var/lib/mysql/mysql.sock
#定义默认时间戳
explicit_defaults_for_timestamp=true
#设置运行用户
user=mysql

三、加入开机启动

systemctl enable mysqld 
systemctl daemon-reload

四、查看默认root密码

cat /var/log/mysqld.log |grep 'temporary password'
[root@localhost]#[Note] A temporary password is generated for root@localhost: iefe_ggtr; #其中 iefe_ggtr; 就是初始密码了。

*如果查询不到密码,需要初始化数据库,生成默认系统库表

mysqld --initialize --user=mysql --console
#运行结果:
[root@localhost /]# mysqld --initialize --user=mysql --console 
[root@localhost /]# grep 'temporary password' /var/log/mysqld.log 
[Note] A temporary password is generated for root@localhost: iefe_ggtr

五、登录MySQL

[root@localhost]# mysql -uroot -p
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or g.
Your MySQL connection id is 3
Server version: 5.7.23
 
mysql->

六、设置密码

登录后需要对初始密码进行重置操作,否则不能进行下一步的数据库操作。

mysql> SET PASSWORD FOR 'root'@'localhost' = PASSWORD('e0+fde1/==='); #重置密码,密码不能太简单
mysql> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| performance_schema |
| sys                |
+--------------------+
4 rows in set (0.00 sec)

本文centos7安装MySQL教程到此结束。激流勇进者方能领略江河源头的奇观胜景。小编再次感谢大家对我们的支持!

标签: MySQL