CentOS7 installation configuration MySQL

Keywords: MySQL RPM yum socket

It's different from ordinary software. Instead of installing rpm directly, install rpm first to get the yum source, and then use Yum to install it

  1. Download rpm package

    [root@VM_149_46_centos ~]# wget https://dev.mysql.com/get/mysql57-community-release-el7-11.noarch.rpm
  2. Install rpm package

    [root@VM_149_46_centos ~]# rpm -ivh mysql57-community-release-el7-11.noarch.rpm
  3. yum install MySQL

    [root@VM_149_46_centos ~]# yum install mysql-server
  4. Test MySql

    [root@VM_149_46_centos ~]# mysql
    ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2)

    The reason for the error here is the access permission of / var/lib/mysql

    [root@VM_149_46_centos ~]# sudo chown -R root:root /var/lib/mysql
    [root@VM_149_46_centos ~]# service mysqld restart
    Redirecting to /bin/systemctl restart  mysqld.service
    

    In this way, you can change the file permissions and restart the mysql service

  5. Configure login password and Mysql port

    [root@VM_149_46_centos ~]# mysql -u root
    ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)

    This is a password error. Look up the random password generated by default

    [root@VM_149_46_centos ~]# grep 'temporary password' /var/log/mysqld.log
    2018-02-05T05:50:32.354328Z 1 [Note] A temporary password is generated for root@localhost: :Fda,R:=u0q)

    : Fda,R:=u0q) is the default generated password
    Use the login command and enter the password

    [root@VM_149_46_centos ~]# mysql -u root -p 

    To change the default password:

    mysql > ALTER USER 'root'@'localhost' IDENTIFIED BY 'New password';

    Add port=6666 to / etc/my.cnf file to change the default port number of mysql from 3306 to 6666

    [root@VM_149_46_centos ~]# vim /etc/my.cnf
    
    # For advice on how to change settings please see
    
    
    # http://dev.mysql.com/doc/refman/5.7/en/server-configuration-defaults.html
    
    
    [mysqld]
    
    #
    
    # Remove leading # and set to the amount of RAM for the most important data
    
    
    # cache in MySQL. Start at 70% of total RAM for dedicated server, else 10%.
    
    
    # innodb_buffer_pool_size = 128M
    
    #
    
    # Remove leading # to turn on a very important data integrity option: logging
    
    
    # changes to the binary log between backups.
    
    
    # log_bin
    
    #
    
    # Remove leading # to set options mainly useful for reporting servers.
    
    
    # The server defaults are faster for transactions and fast SELECTs.
    
    
    # Adjust sizes as needed, experiment to find the optimal values.
    
    
    # join_buffer_size = 128M
    
    
    # sort_buffer_size = 2M
    
    
    # read_rnd_buffer_size = 2M
    
    datadir=/var/lib/mysql
    socket=/var/lib/mysql/mysql.sock
    
    
    # Disabling symbolic-links is recommended to prevent assorted security risks
    
    symbolic-links=0
    
    log-error=/var/log/mysqld.log
    pid-file=/var/run/mysqld/mysqld.pid
    
    port=6666
  6. Login test

     [root@VM_149_46_centos ~]# mysql -u root -p

    Sign in with the new password, no problem

  7. complete

Reference link
http://blog.csdn.net/holmofy/article/details/69364800
http://www.linuxidc.com/Linux/2016-09/134940.htm
https://dev.mysql.com/doc/refman/5.6/en/alter-user.html
https://zhidao.baidu.com/question/1704383715138160380.html

Posted by NS on Wed, 15 Apr 2020 12:08:51 -0700