《地平線:西之絕境》搞笑BUG合集 女主歡快跳舞
mysql安裝指南
1配置準備
安裝使用普通使用者(本次安裝統一使用mysql使用者),安裝包使用mysql-5.7.35-el7-x86_64.tar.gz解壓版安裝。
Mysql 5.7.3的安裝配置 | |
---|---|
機器 | 192.168.1.199(es03-qa)、192.168.1.200(app01-qa) |
系統 | CentOS Linux release 7.6.1810 (Core) |
系統核心 | core-4.1-amd64:core-4.1-noarch |
安裝包 | mysql-5.7.13-linux-glibc2.5-x86_64.tar.gz |
安裝路徑 | /home/mysql |
安裝需求 | 已關閉SElinux,已關閉防火牆 |
備註 | 安裝使用普通使用者(本次統一使用MySQL使用者) |
2. mysql安裝
2.1 軟體下載
linux機器wget下載:wget https://cdn.mysql.com//Downloads/MySQL-5.7/mysql-5.7.35-el7-x86_64.tar.gz
win機器瀏覽器/下載工具:https://cdn.mysql.com//Downloads/MySQL-5.7/mysql-5.7.35-el7-x86_64.tar.gz
2.2 壓縮包上傳
fileZilla或者ftp工具上傳壓縮包到 /home/mysql/ 目錄下
2.3 壓縮包解壓縮以及更名
[mysql@es03-qa ~]$ tar -zxvf mysql-5.7.35-el7-x86_64.tar.gz
2.4 修改啟動檔案
命令 [mysql@es03-qa support-files]$ cd /home/mysql/mysql/support-files [mysql@es03-qa support-files]$ vim mysql.server #檔案修改 原檔案 # Set some defaults mysqld_pid_file_path= if test -z "$basedir" then basedir=/usr/local/mysql bindir=/usr/local/mysql/bin if test -z "$datadir" then datadir=/usr/local/mysql/data fi sbindir=/usr/local/mysql/bin libexecdir=/usr/local/mysql/bin else bindir="$basedir/bin" if test -z "$datadir" then datadir="$basedir/data" fi sbindir="$basedir/sbin" libexecdir="$basedir/libexec" fi #修改後 # Set some defaults mysqld_pid_file_path= if test -z "$basedir" then basedir=/home/mysql/mysql5.7.3 bindir=/home/mysql/mysql5.7.3/bin if test -z "$datadir" then datadir=/home/mysql/mysql5.7.3/data fi sbindir=/home/mysql/mysql5.7.3/bin libexecdir=/home/mysql/mysql5.7.3/bin else bindir="$basedir/bin" if test -z "$datadir" then datadir="$basedir/data" fi sbindir="$basedir/sbin" libexecdir="$basedir/libexec" fi
2.5 初始化
[mysql@es03-qa mysql5.7.3]$ bin/mysqld --initialize --user=mysql --basedir=/home/mysql/mysql5.7.3 --datadir=/home/mysql/mysql5.7.3/data
2021-09-14T10:17:20.574181Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2021-09-14T10:17:20.920371Z 0 [Warning] InnoDB: New log files created, LSN=45790
2021-09-14T10:17:20.974696Z 0 [Warning] InnoDB: Creating foreign key constraint system tables.
2021-09-14T10:17:21.034047Z 0 [Warning] No existing UUID has been found, so we assume that this is the first time that this server has been started. Generating a new UUID: f2657f22-1544-11ec-8b09-000c2938bea4.
2021-09-14T10:17:21.035010Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened.
2021-09-14T10:17:21.945763Z 0 [Warning] A deprecated TLS version TLSv1 is enabled. Please use TLSv1.2 or higher.
2021-09-14T10:17:21.945797Z 0 [Warning] A deprecated TLS version TLSv1.1 is enabled. Please use TLSv1.2 or higher.
2021-09-14T10:17:21.946862Z 0 [Warning] CA certificate ca.pem is self signed.
2021-09-14T10:17:22.745792Z 1 [Note] A temporary password is generated for root@localhost: _LpSGgy9rXOi
#以上為初始化生成的隨機密碼
2.6 授權操作
[mysql@es03-qa mysql5.7.3]$ bin/mysql_ssl_rsa_setup --basedir=/home/mysql/mysql5.7.3 --datadir=/home/mysql/mysql5.7.3/data
2.7 配置mysql使用者環境變數
[mysql@es03-qa ~]$ vim ~/.bash_profile
#檔案修改前
# .bash_profile
# Get the aliases and functions
if [ -f ~/.bashrc ]; then
. ~/.bashrc
fi
# User specific environment and startup programs
PATH=$PATH:$HOME/.local/bin:$HOME/bin
export PATH
修改後
# .bash_profile
# Get the aliases and functions
if [ -f ~/.bashrc ]; then
. ~/.bashrc
fi
# User specific environment and startup programs
PATH=$PATH:$HOME/.local/bin:$HOME/bin
PATH=/home/mysql/mysql5.7.3/bin:$PATH
export PATH
2.8 centos7系列刪除mariadb 需要root
[root@es03-qa ~]# rpm -qa|grep mariadb
mariadb-libs-5.5.60-1.el7_5.x86_64
[root@es03-qa ~]# rpm -e --nodeps mariadb-libs-5.5.60-1.el7_5.x86_64
2.9 服務啟停
[mysql@es03-qa support-files]$ pwd
/home/mysql/mysql5.7.3/support-files
[mysql@es03-qa support-files]$ ./mysql.server start
Starting MySQL.[ OK ]
[mysql@es03-qa support-files]$ mysql.server status #檢視狀態
[mysql@es03-qa support-files]$ mysql.server stop #停止mysql
2.10 配置服務自啟動
[root@es03-qa ~]# cp /home/mysql/mysql5.7.3/support-files/mysql.server /etc/init.d/mysqld
[root@es03-qa ~]# vim /usr/lib/systemd/system/mysql.service
[Unit]
Description=MySQL Server
After=network.target
After=syslog.target
[Service]
User=mysql
Group=mysql
Type=forking
PermissionsStartOnly=false
ExecStart= /etc/init.d/mysqld start
ExecStop= /etc/init.d/mysqld stop
ExecReload= /etc/init.d/mysqld restart
LimitNOFILE = 5000
[Install]
WantedBy=multi-user.target
[root@es03-qa ~]# systemctl daemon-reload #重新載入一下服務的配置檔案
[root@es03-qa ~]# systemctl start mysql.service #開啟mysql服務
[root@es03-qa ~]# systemctl stop mysql.service #關閉mysql服務
[root@es03-qa ~]# systemctl enable mysql.service #配置開機自啟
3.mysql資料庫的配置
3.1資料庫有關配置
[mysql@es03-qa support-files]$ mysql -uroot -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.7.35
Copyright (c) 2000, 2021, Oracle and/or its affiliates.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql> SET PASSWORD=PASSWORD('123456'); #密碼重置
Query OK, 0 rows affected, 1 warning (0.00 sec)
mysql> ALTER USER 'root'@'localhost' PASSWORD EXPIRE NEVER;
Query OK, 0 rows affected (0.00 sec)
mysql> flush privileges;
Query OK, 0 rows affected (0.01 sec)
[mysql@es03-qa support-files]$ mysql -uroot -p123456
mysql: [Warning] Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 3
Server version: 5.7.35 MySQL Community Server (GPL)
Copyright (c) 2000, 2021, Oracle and/or its affiliates.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
4.主從庫的配置
1.另一臺mysql 配置同2,3步驟
[mysql@app01-qa support-files]$ cd /home/mysql/mysql/support-files
[mysql@app01-qa support-files]$ vim mysql.server
#檔案修改 原檔案
# Set some defaults
mysqld_pid_file_path=
if test -z "$basedir"
then
basedir=/usr/local/mysql
bindir=/usr/local/mysql/bin
if test -z "$datadir"
then
datadir=/usr/local/mysql/data
fi
sbindir=/usr/local/mysql/bin
libexecdir=/usr/local/mysql/bin
else
bindir="$basedir/bin"
if test -z "$datadir"
then
datadir="$basedir/data"
fi
sbindir="$basedir/sbin"
libexecdir="$basedir/libexec"
fi
#修改後
# Set some defaults
mysqld_pid_file_path=
if test -z "$basedir"
then
basedir=/home/mysql/mysql5.7.3
bindir=/home/mysql/mysql5.7.3/bin
if test -z "$datadir"
then
datadir=/home/mysql/mysql5.7.3/data
fi
sbindir=/home/mysql/mysql5.7.3/bin
libexecdir=/home/mysql/mysql5.7.3/bin
else
bindir="$basedir/bin"
if test -z "$datadir"
then
datadir="$basedir/data"
fi
sbindir="$basedir/sbin"
libexecdir="$basedir/libexec"
fi
[mysql@app01-qa mysql5.7.3]$ bin/mysqld --initialize --user=mysql --basedir=/home/mysql/mysql5.7.3 --datadir=/home/mysql/mysql5.7.3/data
2021-09-14T11:01:52.836212Z 0 [Warning] Changed limits: max_open_files: 1024 (requested 5000)
2021-09-14T11:01:52.836537Z 0 [Warning] Changed limits: table_open_cache: 431 (requested 2000)
2021-09-14T11:01:52.837060Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2021-09-14T11:01:53.076230Z 0 [Warning] InnoDB: New log files created, LSN=45790
2021-09-14T11:01:53.134881Z 0 [Warning] InnoDB: Creating foreign key constraint system tables.
2021-09-14T11:01:53.192914Z 0 [Warning] No existing UUID has been found, so we assume that this is the first time that this server has been started. Generating a new UUID: 2b209518-154b-11ec-bc32-000c290007c6.
2021-09-14T11:01:53.193924Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened.
2021-09-14T11:01:54.929055Z 0 [Warning] A deprecated TLS version TLSv1 is enabled. Please use TLSv1.2 or higher.
2021-09-14T11:01:54.929080Z 0 [Warning] A deprecated TLS version TLSv1.1 is enabled. Please use TLSv1.2 or higher.
2021-09-14T11:01:54.929833Z 0 [Warning] CA certificate ca.pem is self signed.
2021-09-14T11:01:55.231616Z 1 [Note] A temporary password is generated for root@localhost: +F<4cr*zf;wP
[mysql@app01-qa ~]$ vim ~/.bash_profile
#檔案修改前
# .bash_profile
# Get the aliases and functions
if [ -f ~/.bashrc ]; then
. ~/.bashrc
fi
# User specific environment and startup programs
PATH=$PATH:$HOME/.local/bin:$HOME/bin
export PATH
修改後
# .bash_profile
# Get the aliases and functions
if [ -f ~/.bashrc ]; then
. ~/.bashrc
fi
# User specific environment and startup programs
PATH=$PATH:$HOME/.local/bin:$HOME/bin
PATH=/home/mysql/mysql5.7.3/bin:$PATH
export PATH
[root@app01-qa ~]# rpm -qa|grep mariadb
mariadb-libs-5.5.60-1.el7_5.x86_64
[root@app01-qa ~]# rpm -e --nodeps mariadb-libs-5.5.60-1.el7_5.x86_64
[mysql@app01-qa support-files]$ ./mysql.server start
Starting MySQL.[ OK ]
[mysql@app01-qa support-files]$ pwd
/home/mysql/mysql5.7.3/support-files
[mysql@app01-qa support-files]$ ./mysql.server start
Starting MySQL.[ OK ]
[mysql@app01-qa support-files]$ mysql.server status #檢視狀態
[mysql@app01-qa support-files]$ mysql.server stop #停止mysql
[mysql@app01-qa support-files]$ mysql -uroot -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.7.35
Copyright (c) 2000, 2021, Oracle and/or its affiliates.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql> SET PASSWORD=PASSWORD('123456'); #密碼重置
Query OK, 0 rows affected, 1 warning (0.00 sec)
mysql> ALTER USER 'root'@'localhost' PASSWORD EXPIRE NEVER;
Query OK, 0 rows affected (0.00 sec)
mysql> flush privileges;
Query OK, 0 rows affected (0.01 sec)
[mysql@app01-qa support-files]$ mysql -uroot -p123456
mysql: [Warning] Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 3
Server version: 5.7.35 MySQL Community Server (GPL)
Copyright (c) 2000, 2021, Oracle and/or its affiliates.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
2 主庫配置
1.mysql配置
[mysql@app01-qa support-files]$ mysql -uroot -p123456
mysql: [Warning] Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 3
Server version: 5.7.35 MySQL Community Server (GPL)
Copyright (c) 2000, 2021, Oracle and/or its affiliates.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql> grant replication slave on *.* to 'repl_user'@'192.168.1.200' identified by 'repl_user';
Query OK, 0 rows affected, 1 warning (0.00 sec)
# repl_user是我們建立專門用來備份資料庫的使用者
192.168.1.200是從mysql伺服器的ip,注意在部署的時候要根據實際情況替換掉
identified後面的repl_user是repl_user的密碼
mysql> create database taizhitech;
Query OK, 1 row affected (0.00 sec)
#taizhi使用者配置遠端登陸
mysql> CREATE USER 'repl_user'@'%' IDENTIFIED BY 'repl_user';
Query OK, 0 rows affected (0.01 sec)
#taizhi使用者配置本地登入
mysql> CREATE USER 'repl_user'@'localhost' IDENTIFIED BY 'repl_user';
Query OK, 0 rows affected (0.00 sec)
# 給taizhi使用者操作taizhitech的許可權:
mysql> grant all privileges on taizhitech.* to repl_user;
Query OK, 0 rows affected (0.00 sec)
# 給使用者taizhi在所有登陸ip的許可權:
mysql> grant all privileges on *.* to 'rep1_user'@'%' identified by 'repl_user';
Query OK, 0 rows affected, 1 warning (0.00 sec)
#重新整理許可權
mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)
#使用測試
mysql> use taizhitech
Database changed
mysql> create table TEST(id int(6),name varchar(20));
Query OK, 0 rows affected (0.01 sec)
mysql> insert into TEST values(1,'wuji');
Query OK, 1 row affected (0.01 sec)
mysql> insert into TEST values(2,'zhaomin');
Query OK, 1 row affected (0.00 sec)
mysql> Select * from TEST;
+------+---------+
| id | name |
+------+---------+
| 1 | wuji |
| 2 | zhaomin |
+------+---------+
2 rows in set (0.00 sec)
2 配置檔案配置
[mysql@es03-qa support-files]$ pwd
/home/mysql/mysql5.7.3/support-files
[mysql@es03-qa support-files]$ vim my-default.cnf #文末新增內容如下
[mysql@es03-qa support-files]$ cat my-default.cnf
log_bin=mysql-bin
binlog_format = mixed
server_id =1
read-only=0
binlog-do-db=taizhitech
binlog-ignore-db=information_schema
binlog-ignore-db=performance_schema
binlog-ignore-db=mysql
binlog-ignore-db=test
auto-increment-increment=2
auto-increment-offset=1
[mysql@es03-qa support-files]$ cp my-default.cnf /home/mysql/mysql5.7.3/my.cnf
[mysql@es03-qa support-files]$ ./mysql.server restart
3 主節點狀態
[mysql@es03-qa support-files]$ mysql -uroot -p123456
mysql: [Warning] Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.7.35-log MySQL Community Server (GPL)
Copyright (c) 2000, 2021, Oracle and/or its affiliates.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql> show master status\G
*************************** 1. row ***************************
File: mysql-bin.000001
Position: 353
Binlog_Do_DB: taizhitech
Binlog_Ignore_DB: information_schema,performance_schema,mysql,test
Executed_Gtid_Set:
1 row in set (0.00 sec)
3 從庫配置
[mysql@app01-qa support-files]$ pwd
/home/mysql/mysql5.7.3/support-files
[mysql@app01-qa support-files]$ vim my-default.cnf #文末新增內容如下
[mysql@app01-qa support-files]$ cat my-default.cnf
log-bin = mysql-bin
binlog_format = mixed
server_id = 2
replicate-do-db=eipdb
replicate-ignore-db=information_schema
replicate-ignore-db=performance_schema
replicate-ignore-db=mysql
replicate-ignore-db=test
relay_log=mysqld-relay-bin
log-slave-updates = ON
[mysql@app01-qa support-files]$ cp my-default.cnf /home/mysql/mysql5.7.3/my.cnf
[mysql@app01-qa support-files]$ ./mysql.server restart
Shutting down MySQL..[ OK ]
Starting MySQL.[ OK ]
[mysql@app01-qa support-files]$ mysql -uroot -p123456
mysql: [Warning] Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.7.35-log MySQL Community Server (GPL)
Copyright (c) 2000, 2021, Oracle and/or its affiliates.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql> CHANGE MASTER TO MASTER_HOST='192.168.1.199', MASTER_USER='repl_user',
-> MASTER_PASSWORD='repl_user', MASTER_LOG_FILE='mysql-bin.000002', MASTER_LOG_POS=353;
Query OK, 0 rows affected, 2 warnings (0.00 sec)
#引數註釋
## CHANGE MASTER TO
## -> MASTER_HOST='192.168.1.199',主資料庫的ip,部署時根據實際情況,將其替換
## -> MASTER_USER='repl_user',備份資料庫使用者
## -> MASTER_PASSWORD='repl_user',備份資料庫密碼
## -> MASTER_LOG_FILE='mysql-bin.000001', 主庫show master status\G
## -> MASTER_LOG_POS=154;主庫show master status\G
mysql> commit;
Query OK, 0 rows affected (0.00 sec)
mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)
[mysql@app01-qa support-files]$ ./mysql.server restart
Shutting down MySQL..[ OK ]
Starting MySQL.[ OK ]
[mysql@app01-qa support-files]$ mysql -uroot -p123456
mysql: [Warning] Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 4
Server version: 5.7.35-log MySQL Community Server (GPL)
Copyright (c) 2000, 2021, Oracle and/or its affiliates.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql> show slave status\G
*************************** 1. row ***************************
Slave_IO_State: Waiting for master to send event
Master_Host: 192.168.1.199
Master_User: repl_user
Master_Port: 3306
Connect_Retry: 60
Master_Log_File: mysql-bin.000001
Read_Master_Log_Pos: 154
Relay_Log_File: mysqld-relay-bin.000003
Relay_Log_Pos: 320
Relay_Master_Log_File: mysql-bin.000001
Slave_IO_Running: Yes #節點執行情況
Slave_SQL_Running: Yes #節點執行情況
Replicate_Do_DB: taizhitech
Replicate_Ignore_DB: information_schema,performance_schema,mysql,test
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: 154
Relay_Log_Space: 528
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: 0
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: 1
Master_UUID: f2657f22-1544-11ec-8b09-000c2938bea4
Master_Info_File: /home/mysql/mysql5.7.3/data/master.info
SQL_Delay: 0
SQL_Remaining_Delay: NULL
Slave_SQL_Running_State: Slave has read all relay log; waiting for more updates
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:
1 row in set (0.00 sec)
5 mysql啟動失敗解決方案
[mysql@es03-qa support-files]$ ./mysql.server start
Starting MySQL./home/mysql/mysql5.7.3/bin/mysqld_safe: line 626: /var/log/mariadb/mariadb.log: No such file or directory
2021-09-14T10:30:04.106531Z mysqld_safe error: log-error set to '/var/log/mariadb/mariadb.log', however file don't exists. Create writable for user 'mysql'.
/home/mysql/mysql5.7.3/bin/mysqld_safe: line 144: /var/log/mariadb/mariadb.log: No such file or directory
The server quit without updating PID file (/var/lib/mysql/es03-qa.pid).[FAILED]
出現這個的原因有很多種,下面來分析一下mysql的各個檔案:
(1) mysql.server,在/home/mysql/mysql5.7.3/support-files/下。這是個指令碼檔案,這個指令碼的主要作用就是為了方便啟動和關閉mysql服務。它包含mysqld和mysqld_safe,這兩者都可以用來啟動指令碼。
(2) 日誌檔案,在/home/mysql/mysql5.7.3/data/下,以hostname.err命名,本例為[email protected]。
(3) sock檔案,在/tmp/目錄下,有mysql.sock和mysql.sock.lock兩個檔案。
mysql.sock.lock裡面是mysql的程序號。重啟mysql就會自動更新或者建立。
mysql.sock,這是本機啟動mysql需要的檔案。一般重啟mysql就會自動建立。這個檔案不存在,mysql可以啟動,但是進入mysql命令列客戶端會報錯:# mysql 出錯ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/data/mysql.sock'。
(4) pid檔案,在/home/mysql/mysql5.7.3/data/下,以hostname.pid命名,本例為[email protected]。裡面存放的是mysql的程序號。啟動mysql就會自動建立,關閉mysql就會消失。只要沒有啟動起來,pid檔案就不存在,就會報上面的錯誤。
(5) my.cnf配置檔案,一般在/etc/下。
啟動mysql時,它首先會依次尋找my.cnf這個配置檔案。(若都沒有my.cnf檔案,會另外自動尋找別的配置檔案)
Default options are read from the following files in the given order:
/etc/my.cnf /etc/mysql/my.cnf /usr/local/mysql/etc/my.cnf ~/.my.cnf
如上所示,它會先尋找/etc,再找/etc/mysql,再找/user/local/mysql,再找本地安裝目錄下的my.cnf。並且它的優先順序是遞增的,/etc最低,本地安裝目錄最高,優先順序高的my.cnf會覆蓋優先順序低的my.cnf。
總結一下,解決這個問題的幾種方法。
(1)My.cnf引起的問題
若電腦之前安裝過別的版本的mysql,它在其他地方生成了my.cnf檔案,而mysql5.7.3這個版本並不會自動生成my.cnf檔案,這就會導致它啟動時還會用之前的my.cnf檔案,所以無法啟動。解決這個辦法,有兩種途徑。1是把my.cnf檔案全部刪除,2是在優先順序最高的本地安裝目錄建一個新的my.cnf檔案。這裡現在比較簡單的第二種解決方法。
解決方法:
[mysql@es03-qa support-files]$ pwd
/home/mysql/mysql5.7.3/support-files
[mysql@es03-qa support-files]$ cp my-default.cnf /home/mysql/mysql5.7.3/my.cnf
[mysql@es03-qa support-files]$ cd ..
[mysql@es03-qa support-files]$ vim my.cnf
#檔案修改 原檔案
# Set some defaults
mysqld_pid_file_path=
if test -z "$basedir"
then
basedir=/usr/local/mysql
bindir=/usr/local/mysql/bin
if test -z "$datadir"
then
datadir=/usr/local/mysql/data
fi
sbindir=/usr/local/mysql/bin
libexecdir=/usr/local/mysql/bin
else
bindir="$basedir/bin"
if test -z "$datadir"
then
datadir="$basedir/data"
fi
sbindir="$basedir/sbin"
libexecdir="$basedir/libexec"
fi
#修改後
# Set some defaults
mysqld_pid_file_path=
if test -z "$basedir"
then
basedir/home/mysql/mysql5.7.3
bindir=/home/mysql/mysql5.7.3/bin
if test -z "$datadir"
then
datadir=/home/mysql/mysql5.7.3/data
fi
sbindir=/home/mysql/mysql5.7.3/bin
libexecdir=/home/mysql/mysql5.7.3/bin
else
bindir="$basedir/bin"
if test -z "$datadir"
then
datadir="$basedir/data"
fi
sbindir="$basedir/sbin"
libexecdir="$basedir/libexec"
fi
# log-error是錯誤日誌存放的位置,系統預設放在/home/mysql/mysql5.7.3/data下的es03-qa.err。
# pid-file是存放程序號的檔案系統預設會在啟動時在/home/mysql/mysql5.7.3/data目錄下自動建立一個es03-qa.pid。
[mysqld_safe]
log-error=
pid-file=
#儲存退出 重啟mysql
(2)多餘的mysql程序引起的問題
[mysql@es03-qa support-files]$ ps -ef|grep mysqld
mysql 26286 1 0 18:34 pts/0 00:00:00 /bin/sh /home/mysql/mysql5.7.3/bin/mysqld_safe --datadir=/home/mysql/mysql5.7.3/data --pid-file=/home/mysql/mysql5.7.3/data/es03-qa.pid
mysql 26377 26286 0 18:34 pts/0 00:00:01 /home/mysql/mysql5.7.3/bin/mysqld --basedir=/home/mysql/mysql5.7.3 --datadir=/home/mysql/mysql5.7.3/data --plugin-dir=/home/mysql/mysql5.7.3/lib/plugin --log-error=es03-qa.err --pid-file=/home/mysql/mysql5.7.3/data/es03-qa.pid
mysql 27610 26241 0 18:47 pts/0 00:00:00 grep --color=auto mysqld
[mysql@es03-qa support-files]$ Kill -9 26377
(3)sock檔案引起的問題。
啟動mysql時,mysql.sock和mysql.sock.lock沒有及時更新,需要使用命令:rm -rf mysql.sock,rm -rf mysql.sock.lock。然後再啟動mysql服務,它就會及時生成新的sock檔案。
(4)mysql-bin.index引起的問題。
去mysql的資料目錄/data看看,如果存在mysql-bin.index,就趕快把它刪除掉。可能是第二次在機器上安裝mysql,有殘餘資料影響了服務的啟動。
6 主從配置失敗
在從資料庫配置時:
輸入命令:show slave status\G,執行後看到Slave_IO_Running和Slave_SQL_Running沒有為Yes。那表示沒有配置成功(廢話)。
我遇到的情況是這樣:
mysql> show slave status\G
Slave_IO_Running: Yes
Slave_SQL_Running: No
解決方法:
(1)先stop slave,停掉slave服務
(2)到主伺服器上檢視主機狀態:
記錄File和Position對應的值。
mysql> show master status\G
*************************** 1. row ***************************
File: mysql-bin.000002
Position: 1593
Binlog_Do_DB: taizhitech
Binlog_Ignore_DB: information_schema,performance_schema,mysql,test
Executed_Gtid_Set:
1 row in set (0.00 sec)
(3)到slave伺服器上執行手動同步:
mysql> change master to
> master_host='192.168.219.119',
> master_user='repl_user',
> master_password='repl2016',
> master_port=3306,
> master_log_file='mysql-bin.000002',
> master_log_pos=3153;
(4)再次檢視slave狀態發現:
Slave_IO_Running: Yes
Slave_SQL_Running: Yes
不過也有可能出現:
mysql> show slave status\G
Slave_IO_Running: No
Slave_SQL_Running: Yes
解決方法:
(1)在主資料庫的命令列客戶端:看一下是否授權給
mysql> show grants for 'repl_user'@'192.168.1.200';
+---------------------------------------------------------------+
| Grants for [email protected] |
+---------------------------------------------------------------+
| GRANT REPLICATION SLAVE ON *.* TO 'repl_user'@'192.168.1.200' |
+---------------------------------------------------------------+
(2)根據之上的結果。已經賦予了許可權。
[mysql@app01-qa ~]$ mysql -uroot -h 192.168.1.199 -p123456
mysql: [Warning] Using a password on the command line interface can be insecure.
ERROR 1045 (28000): Access denied for user 'root'@'app01-qa' (using password: YES)
[mysql@app01-qa ~]$ mysql -urepl_user -h 192.168.1.199 -prepl_user
mysql: [Warning] Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 5
Server version: 5.7.35-log MySQL Community Server (GPL)
Copyright (c) 2000, 2021, Oracle and/or its affiliates.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql> exit
Bye
(3)好像也登陸進去了。於是再一次執行了第一個的解決方法,先停掉slave,再設定,再重啟資料庫。
(4)於是在檢視從資料庫的狀態,都是yes了