当前位置:Gxlcms > 数据库问题 > mysql8更改大小写敏感(现网环境)

mysql8更改大小写敏感(现网环境)

时间:2021-07-01 10:21:17 帮助过:26人阅读

操作服务器:主数据库

#备份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:

 

------------恢复内容结束------------

mysql8更改大小写敏感(现网环境)

标签:usr   修改   服务   rem   generated   creat   expand   cas   change   

人气教程排行