$cdmysql-master# Init the data dir first# bin/mysqld --defaults-file=./my.cnf --initialize --user=mysql$bin/mysqld--initialize--user=mysqlAtemporarypasswordisgeneratedforroot@localhost:r_/(wD0p3;Im# bin/mysqld --defaults-file=/etc/my.cnf &$bin/mysqld--defaults-file=/etc/my.cnf# test Server$bin/mysqladmin-S/var/run/mysqld/mysqld.sock-uroot-pversion$bin/mysqladmin-S/var/run/mysqld/mysqld.sock-uroot-pshutdown$bin/mysqlshow-S/var/run/mysqld/mysqld.sock-uroot-p$bin/mysqlshow-S/var/run/mysqld/mysqld.sock-uroot-pmysql$bin/mysql--defaults-file=/etc/my.cnf-uroot-p-e"select host, user from user"mysql# Another terminal$bin/mysql-S/var/run/mysqld/mysqld.sock-P3308-uroot-p# alter user root@'127.0.0.1' IDENTIFIED WITH caching_sha2_password BY '123456';mysql> ALTERUSER'root'@'localhost'IDENTIFIEDBY'123456';mysql> CREATEUSER'root'@'127.0.0.1'IDENTIFIEDBY'root-password';mysql> CREATEUSER'root'@'::1'IDENTIFIEDBY'root-password';
主从同步配置
### Master# edit my.cnf, add[mysqld]server-id=1log-bin=mysql-bin# Restart MySQL server# Create a slave usermysql> createuser'slave'@'%'identifiedby'123456';mysql> grantREPLICATIONSLAVE,REPLICATIONCLIENTon*.*to'slave'@'%';# Get File and Positionmysql> showmasterstatus; # 备份数据$bin/mysqldump-h127.0.0.1-P3306-uroot-p--databasestest>test.dump# 恢复数据$bin/mysql-h127.0.0.1-P3308-uroot-p<test.dump### Slave1# edit my.cnf[mysqld]server-id=10log-bin=mysql-slave-binrelay-log=mysql-relay-bin# Restart MySQL server# bind Master-Slave# --get-server-public-keymysql> change master to master_host='127.0.0.1', master_user='slave', master_password='123456', master_port=3308, master_log_file='mysql-bin.000001', master_log_pos=712, master_connect_retry=30;
Note: MySQL 8.0 配置主从同步和之前的版本有些区别,需要特别注意。
MySQL 特性
字符集与比较规则
字符集:ASCII / ISO 8859-1(latin1) / GB2312 / GBK / utf8
// 查看支持的字符集
show charset;
show CHARACTER SET;
// 查看比较规则
show collation [like 匹配模式];
show collation like 'utf8\_%';