CentOS6.7 install mysql5.7.18


  1,  Unzip to /usr/local catalog

    # tar -zxvf mysql-5.7.18-linux-glibc2.5-i686.tar.gz -C /usr/local

  2,  mysql-5.7.18-linux-glibc2.5-i686 Rename folder to mysql

    # cd /usr/local

    # mv mysql-5.7.18-linux-glibc2.5-i686/ mysql

  3,  newly build mysql User groups and mysql user

    # groupadd mysql

    # useradd -r -g mysql mysql

  4,  New data directory

    # cd /usr/local/mysql

    # mkdir data

  5,  Change owner and authorization 755

    # cd /usr/local

    # chown -R mysql:mysql mysql/

    # chmod -R 755 mysql/

  6,  initialization mysqld

    # cd /usr/local/mysql

    # ./bin/mysqld --user=mysql --basedir=/usr/local/mysql
--datadir=/usr/local/mysql/data --initialize


     Record it root Initial password for : GjlI08>p4kDw

  7,  take mysqld Add as service , And start it

    # cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld

     establish mysql Default profile /etc/my.cnf, And add content in the picture


    # vim /etc/my.cnf

     Save and exit my.cnf, start-up mysqld

    # service mysqld start

     The following message appears to indicate successful startup


     see mysql Start successfully or not

    # ps -ef|grep mysql

     The following message appears to indicate successful startup


     You can also check mysqld Status of

    # service mysqld status


  8,  Sign in mysql And modify root password

    # cd /usr/local/mysql

    # ./bin/mysql -uroot –p

     Enter initial password , step 6 Build in , The following message appears to indicate successful login


     modify root password

    mysql> SET PASSWORD = PASSWORD('123456');


     Initial login not modified root Password for , The following error prompts will appear when operating the database , Then it needs to be modified root User's password

      ERROR 1820 (HY000): You must reset your password using ALTER USER
statement before executing this statement.

  9,  set up mysql Remote accessible ( The premise is that the firewall must be closed ,chkconfig iptables off: Set auto start to off ,service
iptables stop: Turn off firewall )

     Log in to mysql

    mysql> use mysql

    mysql> update user set host = '' where user = 'root';

    mysql> FLUSH PRIVILEGES; Remote access to local mysql Remote ip, If you want to ip Local access mysql, Then just change into % that will do

    mysql> update user set host = '%' where user = 'root';

mysql Master-slave replication

  windows upper mysql do master,linux upper mysql do slave,mysql Version is 5.7.18;windows Of ip by,linux Of ip by

  1,master Upper open binlog journal

          stay mysql Of home Directory found my.ini file ( New if not ), The configuration is as follows
[mysqld] # set basedir to your installation path basedir=D:\\mysql-5.7.18 #
set datadir to the location of your data directory datadir=D:\\mysql-5.7.18
\\data port= 3306

log-bin = mysql-bin #[ must ] Enable binary logging server-id = 4 #[ must ] Server unique ID, The default is 1, It's better to take ip After 3 position
expire-logs-days = 7 # Keep only 7 Binary log for days , In case the disk is full of logs binlog-ignore-db = mysql # Databases not backed up
binlog-ignore-db = information_schema binlog-ignore-db = performation_schema
binlog-ignore-db = sys binlog-do-db=mybatis # Database name to be copied
          test log_bin Open successfully or not

         mysql> show variables like '%log_bin%';

          The following figure appears ,log_bin by ON It means the opening is successful ,OFF Indicates open failed


  2,master Set up backup account in database of
:backup Is the user name ,% Represents any remote address , The password is as follows 1234 Of any remote address backup Can be connected master host

    mysql> grant replication slave on *.* to 'backup'@'%' identified by '1234';

    mysql> use mysql

    mysql> select user,authentication_string,host from user;

     You can see the backup account we just created :


  3, Copy data

          restart MySQL Service and set read lock

      net stop MySQL

      net start MySQL

       Sign in mysql

           mysql> flush tables with read lock;

     Read lock means read only , Cannot update , For a consistent snapshot

     View the current binary log name and offset values on the primary server    

    mysql> show master status \G


     The process of copying is as follows :


    File Represents the log that implements the replication function , That is, in the figure above Binary
log;Position Means binlog The offset of the log file will be synchronized to the slave in , Before the offset, we need to import it manually

         from master Export data , Then import to slave in

                 Open another command window , use mysqldump Command to export data


       take d:\a.txt copy to slave upper , Then import to mysql In the database ,slave On mybatis Create first if database does not exist , Then import


       Export yes mysqldump, Import yes mysql

  4, to configure slave(

         slave yes linux Environmental Science ,mysql The configuration file for is /etc/my.cnf, New if it doesn't exist , Match with the following
[mysqld] basedir=/usr/local/mysql datadir=/usr/local/mysql/data socket=/tmp/
mysql.sock user=mysql port=3306 log-bin=mysql-bin server-id=223
         restart slave database

      # service mysqld restart

         Sign in slave database , And make the following settings

      mysql> stop slave;

      mysql> change master to






                 Meaning of each parameter :

                master_host The IP address

                master_user Remote login for replication master Of mysql Users of , In step 2 With settings

                master_password Remote login for replication master Of mysql Face of , In step 2 With settings

                master_log_file Implementing replicated binlog log file In step 3 In the red frame

                master_log_pos Implementing replicated binlog Offset of log file In step 3 In the red frame

      mysql> start slave;

     see slave Status of slave

                mysql> show slave status \G



       If the values of the two items marked in the figure are Yes, It means slave Set successfully

  5, Turn off the read lock of the primary database

         mysql> unlock tables;

  6, test

     If there's no problem ahead , that master All data operations on will be synchronized to the slave upper

Document address

   Click here