CentOS7下通过yum安装mysql

CentOS7的yum源中默认好像是没有mysql的。为了解决这个问题,我们要先下载mysql的repo源

下载myql的repo源
 wget http://repo.mysql.com/mysql-community-release-el7-5.noarch.rpm

安装mysql-community-release-el7-5.noarch.rpm包
 rpm -ivh mysql-community-release-el7-5.noarch.rpm

安装mysql
 yum install mysql-server
 根据步骤安装即可,但是安装完成后,root用户默认没有密码,需要重置密码。

安装完成后,检查mysql是否默认已经启动
 service mysql status
  Redirecting to /bin/systemctl status  mysql.service
  mysqld.service - MySQL Community Server
     Loaded: loaded (/usr/lib/systemd/system/mysqld.service; enabled)
     Active: inactive (dead)
  根据上诉信息,说明默认mysql未启动

启动mysql服务
 service mysql start
  Redirecting to /bin/systemctl start  mysql.service

再次检查mysql服务是否启动成功
 service mysql status
  Redirecting to /bin/systemctl status  mysql.service
  mysqld.service - MySQL Community Server
     Loaded: loaded (/usr/lib/systemd/system/mysqld.service; enabled)
     Active: active (running) since Thu 2016-03-31 16:27:15 HKT; 6s ago
    Process: 20000 ExecStartPost=/usr/bin/mysql-systemd-start post (code=exited, status=0/SUCCESS)
    Process: 19933 ExecStartPre=/usr/bin/mysql-systemd-start pre (code=exited, status=0/SUCCESS)
   Main PID: 19999 (mysqld_safe)
     CGroup: /system.slice/mysqld.service
             ├─19999 /bin/sh /usr/bin/mysqld_safe
             └─20152 /usr/sbin/mysqld --basedir=/usr --datadir=/var/lib/mysql -...

  Mar 31 16:27:14 localhost.localdomain mysql-systemd-start[19933]: Support MyS...
  Mar 31 16:27:14 localhost.localdomain mysql-systemd-start[19933]: Note: new d...
  Mar 31 16:27:14 localhost.localdomain mysql-systemd-start[19933]: Please make...
  Mar 31 16:27:14 localhost.localdomain mysql-systemd-start[19933]: WARNING: De...
  Mar 31 16:27:14 localhost.localdomain mysql-systemd-start[19933]: This file w...
  Mar 31 16:27:14 localhost.localdomain mysql-systemd-start[19933]: If you do n...
  Mar 31 16:27:14 localhost.localdomain mysql-systemd-start[19933]: --defaults-...
  Mar 31 16:27:14 localhost.localdomain mysqld_safe[19999]: 160331 16:27:14 mys...
  Mar 31 16:27:14 localhost.localdomain mysqld_safe[19999]: 160331 16:27:14 mys...
  Mar 31 16:27:15 localhost.localdomain systemd[1]: Started MySQL Community Ser...
  Hint: Some lines were ellipsized, use -l to show in full.
  根据上诉信息,说明默认mysql已经启动成功

登录mysql
 因为mysql安装完成后,root用户默认没有密码,在终端输入:mysql -uroot 或 mysql,即可登录到mysql

重置root用户密码
 mysql> update mysql.user set password=PASSWORD('ytkj') where user='root';
 Query OK, 4 rows affected (0.00 sec)
 Rows matched: 4  Changed: 4  Warnings: 0
 但是此时,我们退出mysql,从终端以:mysql -uroot -pytkj登录,发现登录失败
 所以我们需要重启mysql服务,让之前的修改生效
 service mysql restart
  Redirecting to /bin/systemctl restart  mysql.service
 
还是以旧密码(也就是默认的没有密码)登录mysql
 mysql -uroot 或 mysql
  ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)

下面我们用新密码登录mysql
 mysql -uroot -pytkj
 返现登录成功

至此,CentOS7上安装mysql并修改root用户密码成功。
 
 

 

 

 

 

 


 

你可能感兴趣的:(mysql,yum,CentOS7)