初始化配置
MySQL的啟動方式
可以通過命令行的方式,傳入啟動參數,如果配置文件內的參數和命令行傳入的參數相同,以命令行參數為准
[root@db ~]# ps -ef|grep mydqld root 1179 1058 0 10:17 pts/0 00:00:00 grep --color=auto mydqld [root@db ~]# ps -ef|grep mys root 772 1 0 07:54 ? 00:00:00 /bin/sh /usr/local/mysql8/bin/mysqld_safe --datadir=/data/mysql/data_3306 --pid-file=/data/mysql/data_3306/db.pid mysql 955 772 0 07:54 ? 00:00:43 /usr/local/mysql8/bin/mysqld --basedir=/usr/local/mysql8 --datadir=/data/mysql/data_3306 --plugin-dir=/usr/local/mysql8/lib/plugin --user=mysql --log-error=db.err --pid-file=/data/mysql/data_3306/db.pid --socket=/tmp/myql.sock --port=3306
舉例:忘記root密碼
[root@localhost ~]# /etc/init.d/mysqld stop [root@localhost ~]# mysqld_safe --port=3329 & [root@localhost ~]# ss -lntp State Recv-Q Send-Q Local Address:Port Peer Address:Port LISTEN 0 128 *:22 *:* users:(("sshd",pid=781,fd=3)) LISTEN 0 128 :::3329 :::* users:(("mysqld",pid=2595,fd=29)) LISTEN 0 70 :::33060 :::* users:(("mysqld",pid=2595,fd=32)) LISTEN 0 128 :::22 :::* users:(("sshd",pid=781,fd=4)) [root@localhost ~]# mysql -uroot -p123456
[root@localhost ~]# mysqld_safe --skip-grant-tables --skip-networking &
[root@localhost ~]# mysql
配置文件的加載順序
[root@localhost ~]# mysqld --help --verbose|grep my.cnf
/etc/my.cnf /etc/mysql/my.cnf /usr/local/mysql/etc/my.cnf ~/.my.cnf
初始化配置文件應用
mysql配置文件格式
[標簽] 配置=xxx 配置=xxx 配置=xxx …
[標簽]
標簽分為兩種
server端:
[server]
[mysqld]
[mysqld_safe]
client端(只影響本地連接,不影響遠程):
[client]
[mysql]
[mysqldump]
調用非默認路徑配置文件
mysqld_safe --defaults-file=配置文件路徑 &