美文网首页我爱编程
centos7下使用yum安装mysql

centos7下使用yum安装mysql

作者: Emmalong | 来源:发表于2018-01-15 23:22 被阅读0次

    虽然是根据老徐的那篇(软件测试从业者必备之MYSQL从零到入坑)来安装,但是实际操作过程中还是遇到各种问题,最后还参考了其他文章(eg.http://www.linuxidc.com/Linux/2016-09/135288.htm)才算完全入坑成功。下面主要列一下我的安装过程,以做记录。

    1.检查自带版本数据库

    [root@bogon ~]$ yum list installed |grep sql

    注:我的系统是centos7.0,这里自带的数据库是sqlite,为了不安装那么多,我把它也删掉

    2.删除自带版本

    [root@bogon ~]$ yum -y remove sqlite

    3.下载并安装mysql 的rpm源

    [root@bogon tools]$ wget http://dev.mysql.com/get/mysql57-community-release-el7-8.noarch.rpm --no-check-certificate

    [root@bogon tools]$ yum localinstall mysql57-community-release-el7-8.noarch.rpm

    4.验证本地mysql yum源是否安装成功

    [root@bogon ~]$  yum repolist all |grep mysql

    mysql-connectors-community MySQL Connectors Community enabled: 42

    mysql-connectors-community-source MySQL Connectors Community - So disabled

    mysql-tools-community            MySQL Tools Community          enabled:    55

    mysql-tools-community-source      MySQL Tools Community - Source  disabled

    mysql-tools-preview              MySQL Tools Preview            disabled

    mysql-tools-preview-source        MySQL Tools Preview - Source    disabled

    mysql55-community                MySQL 5.5 Community Server      disabled

    mysql55-community-source          MySQL 5.5 Community Server - So disabled

    mysql56-community                MySQL 5.6 Community Server      disabled

    mysql56-community-source          MySQL 5.6 Community Server - So disabled

    mysql57-community                MySQL 5.7 Community Server      enabled:  247

    mysql57-community-source          MySQL 5.7 Community Server - So disabled

    5.安装mysql

    [root@bogon ~]$  yum install mysql-community-server

    6.启动mysql

    [root@bogon ~]$ systemctl start mysqld

    查看mysql状态

    [root@bogon ~]$ systemctl status mysqld

    7.开机自启动

    [root@bogon ~]$ systemctl enable mysql

    [root@bogon ~]$ systemctl daemon-reload

    至此mysql安装成功,下面进行登录以及远程访问

    8.登录mysql

    [root@bogon ~]# mysql -uroot -p

    Enter password:

    或者:[root@bogon ~]# grep 'temporary password' /var/log/mysqld.log

    注:这里直接回车后或者通过查看临时密码并输入临时密码后仍提示错误:

    ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES)

    解决方法http://blog.csdn.net/myth_xgx/article/details/50809645:

      $ sudo systemctl stop mysqld.service

         $ sudo systemctl set-environment MYSQLD_OPTS="--user=mysql --skip-grant-tables --skip-networking"

         $ sudo systemctl start mysqld.service    

         $ mysql -u root mysql

         mysql > UPDATE mysql.user SET authentication_string=PASSWORD("abcdef")  WHERE user='root' and host='localhost';

         mysql > flush privileges;

         mysql > quit

         $ sudo systemctl unset-environment MYSQLD_OPTS

         $ sudo systemctl restart mysqld.service

    然后再进入mysql并修改密码

    [root@bogon ~]#  mysql -uroot -p

    Enter password:abcdef

    mysql> ALTER USER 'root'@'localhost' IDENTIFIED BY 'MyNewPass11!';

    之后密码为修改后的密码。

    9,远程连接

    mysql> GRANT ALL PRIVILEGES ON *.* TO 'emmalong'@'%' IDENTIFIED BY 'MyNewPass11!' 

    mysql> FLUSH PRIVILEGES;

    mysql> EXIT;

    相关文章

      网友评论

        本文标题:centos7下使用yum安装mysql

        本文链接:https://www.haomeiwen.com/subject/ltmhoxtx.html