mysql8更改大小寫敏感(現網環境)


------------恢復內容開始------------

1、備份數據

操作服務器:主數據庫

#備份mysql中所有數據庫數據
./mysqldump -h主數據庫ip -uroot -p -P3308 --all-databases > /data0/all_db.sql

2、停庫

操作服務器:主備數據庫均操作

systemctl stop mysqld.service
#查看是否有進程
ps -ef|grep mysql

3、更改mysql數據目錄

操作服務器主數據庫,從數據庫

mv  /data0/mysql_data /data0/mysql_data_bak0617

4、修改配置文件

操作服務器:主數據庫,從數據庫

vim /etc/my.cnf

mysqld內最后一行增加:

lower_case_table_names=1

5、初始化mysql

操作服務器:主數據庫,從數據庫

systemctl restart mysqld.service  ###本次重啟無效,需要初始化數據庫,見下方

主庫初始化數據庫

#初始化數據庫,使用mysql用戶,配置文件為自己定義的配置文件路徑
[root@host197 bin]# ./mysqld --defaults-file=/etc/my.cnf --initialize --user=mysql

2021-06-17T09:43:42.456722Z 0 [Warning] [MY-011070] [Server] 'Disabling symbolic links using --skip-symbolic-links (or equivalent) is the default. Consider not using this option as it' is deprecated and will be removed in a future release.
2021-06-17T09:43:42.456830Z 0 [System] [MY-013169] [Server] /usr/local/mysql/bin/mysqld (mysqld 8.0.22) initializing of server in progress as process 120206
2021-06-17T09:43:42.457986Z 0 [Warning] [MY-013242] [Server] --character-set-server: 'utf8' is currently an alias for the character set UTF8MB3, but will be an alias for UTF8MB4 in a future release. Please consider using UTF8MB4 in order to be unambiguous.
2021-06-17T09:43:42.490413Z 1 [System] [MY-013576] [InnoDB] InnoDB initialization has started.
2021-06-17T09:43:47.935612Z 1 [System] [MY-013577] [InnoDB] InnoDB initialization has ended.
2021-06-17T09:44:01.978514Z 6 [Note] [MY-010454] [Server] A temporary password is generated for root@localhost: 4G(bUW.Fwnzd  
### 4G(bUW.Fwnzd為root初始密碼

重啟數據庫

systemctl start mysqld.service

198從庫初始化

先刪除/data0/mysql_data

[root@host198 bin]# ./mysqld --defaults-file=/etc/my.cnf --initialize --user=mysql
2021-06-17T09:48:34.415782Z 0 [Warning] [MY-011070] [Server] 'Disabling symbolic links using --skip-symbolic-links (or equivalent) is the default. Consider not using this option as it' is deprecated and will be removed in a future release.
2021-06-17T09:48:34.415881Z 0 [System] [MY-013169] [Server] /usr/local/mysql/bin/mysqld (mysqld 8.0.22) initializing of server in progress as process 35472
2021-06-17T09:48:34.417050Z 0 [Warning] [MY-013242] [Server] --character-set-server: 'utf8' is currently an alias for the character set UTF8MB3, but will be an alias for UTF8MB4 in a future release. Please consider using UTF8MB4 in order to be unambiguous.
2021-06-17T09:48:34.417631Z 0 [ERROR] [MY-010457] [Server] --initialize specified but the data directory has files in it. Aborting.
2021-06-17T09:48:34.417645Z 0 [ERROR] [MY-013236] [Server] The designated data directory /data0/mysql_data/ is unusable. You can remove all files that the server added to it.
2021-06-17T09:48:34.417730Z 0 [ERROR] [MY-010119] [Server] Aborting
2021-06-17T09:48:34.417908Z 0 [System] [MY-010910] [Server] /usr/local/mysql/bin/mysqld: Shutdown complete (mysqld 8.0.22)  MySQL Community Server - GPL.
[root@host198 bin]# rm -rf /data0/mysql_data
[root@host198 bin]# ./mysqld --defaults-file=/etc/my.cnf --initialize --user=mysql
2021-06-17T09:48:58.637192Z 0 [Warning] [MY-011070] [Server] 'Disabling symbolic links using --skip-symbolic-links (or equivalent) is the default. Consider not using this option as it' is deprecated and will be removed in a future release.
2021-06-17T09:48:58.637291Z 0 [System] [MY-013169] [Server] /usr/local/mysql/bin/mysqld (mysqld 8.0.22) initializing of server in progress as process 35476
2021-06-17T09:48:58.638395Z 0 [Warning] [MY-013242] [Server] --character-set-server: 'utf8' is currently an alias for the character set UTF8MB3, but will be an alias for UTF8MB4 in a future release. Please consider using UTF8MB4 in order to be unambiguous.
2021-06-17T09:48:58.699969Z 1 [System] [MY-013576] [InnoDB] InnoDB initialization has started.
2021-06-17T09:49:08.820121Z 1 [System] [MY-013577] [InnoDB] InnoDB initialization has ended.
2021-06-17T09:49:35.582394Z 6 [Note] [MY-010454] [Server] A temporary password is generated for root@localhost: Rq,iajL#z0s:

 

6、修改用戶名密碼

操作服務器:主數據庫,從數據庫

6.1修改root密碼

操作服務器:主數據庫,從數據庫兩台都修改

#登錄mysql
./mysql -uroot -p --socket=/usr/local/mysql/var/lib/mysql8/mysql8.sock   
#使用上述初始化后的密碼登錄

#命令行下執行修改密碼
alter user 'root'@'localhost' identified by 'Ynyd#1234';

7、在master服務器上添加slave賬號

7.1主庫操作

操作服務器:主數據庫

 ./mysql -uroot -p --socket=/usr/local/mysql/var/lib/mysql8/mysql8.sock        
mysql> create user 'slave'@'從數據庫' identified with mysql_native_password by 'Ynyd#1234'; 
mysql>grant replication slave on *.* to 'slave'@'從數據庫';   
mysql>flush privileges;
 mysql>show master status; ###查看File和Position,為下面的從庫執行start slave做准備
 mysql> select user,host from user;
+------------------+----------------+
| user             | host           |
+------------------+----------------+
| root             | %              |
| slave            | 從數據庫 |
| mysql.infoschema | localhost      |
| mysql.session    | localhost      |
| mysql.sys        | localhost      |
+------------------+----------------+

#初始化后需要使所有服務器能登錄,操作如下
mysql>use mysql;
mysql>update user set user.Host='%'where user.User='root';
mysql>flush privileges;

 

7.2在從庫執行
####配置主庫信息####
mysql> change master to master_host='主數據庫',
    -> master_port=3308,master_user='slave',master_password='Ynyd#1234',master_log_file='master-bin.000001',master_log_pos=1;
#master_host為master的ip
#master_port為master的端口
#master_user在master創建的從庫使用的賬號
#master_log_file在master上使用show master status查詢的File
#master_log_pos在master上使用show master status查詢的Position,為1為從頭開始

mysql> start slave;                                            # 開啟主從同步
Query OK, 0 rows affected (0.00 sec)
mysql> show slave status\G;                                    # 查看主從同步狀態
*************************** 1. row ***************************
               Slave_IO_State: Waiting for master to send event
                  Master_Host: 主數據庫
                  Master_User: slave
                  Master_Port: 3308
                Connect_Retry: 60
              Master_Log_File: master-bin.000002
          Read_Master_Log_Pos: 426779408
               Relay_Log_File: slave-relay-bin.000003
                Relay_Log_Pos: 344142597   #此處只要有數據同步就是變化的
        Relay_Master_Log_File: master-bin.000002
             Slave_IO_Running: Yes	# Slave_IO_Running和Slave_SQL_Running的狀態都為Yes表示主從同步設置成功
            Slave_SQL_Running: Yes  ## Slave_IO_Running和Slave_SQL_Running的狀態都為Yes表示主從同步設置成功
              Replicate_Do_DB: 
          Replicate_Ignore_DB: 
           Replicate_Do_Table: 
       Replicate_Ignore_Table: 
      Replicate_Wild_Do_Table: 
  Replicate_Wild_Ignore_Table: 
                   Last_Errno: 0
                   Last_Error: 
                 Skip_Counter: 0
          Exec_Master_Log_Pos: 344142380
              Relay_Log_Space: 426780051
              Until_Condition: None
               Until_Log_File: 
                Until_Log_Pos: 0
           Master_SSL_Allowed: No
           Master_SSL_CA_File: 
           Master_SSL_CA_Path: 
              Master_SSL_Cert: 
            Master_SSL_Cipher: 
               Master_SSL_Key: 
        Seconds_Behind_Master: 1671
Master_SSL_Verify_Server_Cert: No
                Last_IO_Errno: 0
                Last_IO_Error: 
               Last_SQL_Errno: 0
               Last_SQL_Error: 
  Replicate_Ignore_Server_Ids: 
             Master_Server_Id: 198
                  Master_UUID: 9bfb569a-cf53-11eb-87c5-485702cd7891
             Master_Info_File: mysql.slave_master_info
                    SQL_Delay: 0
          SQL_Remaining_Delay: NULL
      Slave_SQL_Running_State: waiting for handler commit
           Master_Retry_Count: 86400
                  Master_Bind: 
      Last_IO_Error_Timestamp: 
     Last_SQL_Error_Timestamp: 
               Master_SSL_Crl: 
           Master_SSL_Crlpath: 
           Retrieved_Gtid_Set: 
            Executed_Gtid_Set: 
                Auto_Position: 0
         Replicate_Rewrite_DB: 
                 Channel_Name: 
           Master_TLS_Version: 
       Master_public_key_path: 
        Get_master_public_key: 0
            Network_Namespace: 
1 row in set, 1 warning (0.00 sec)

ERROR: 
No query specified

mysql> 

 

8、恢復數據

操作服務器:主數據庫

[root@host197 data0]# mysql -h主數據庫 -uroot -p -P3308 < all_db061717.sql
Enter password:

 

------------恢復內容結束------------


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM