?
本文檔使用 php中文網(wǎng)手冊(cè) 發(fā)布
常規(guī)方法啟動(dòng)數(shù)據(jù)庫(kù)
啟動(dòng)MySQL命令
[root@localhost ~]# /etc/init.d/mysql start Starting MySQL.. [確定]
查看MySQL端口
[root@localhost ~]# netstat -tunpl|grep mysql tcp 0 0 0.0.0.0:3306 0.0.0.0:* LISTEN 2505/mysqld
查看MySQL進(jìn)程
[root@localhost ~]# ps -ef |grep mysqld root 2264 1 0 11:35 pts/0 00:00:00 /bin/sh /usr/local/mysql/bin/mysqld_safe --datadir=/usr/local/mysql/data --pid-file=/usr/local/mysql/data/localhost.pid mysql 2505 2264 0 11:35 pts/0 00:00:00 /usr/local/mysql/bin/mysqld --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data --plugin-dir=/usr/local/mysql/lib/plugin --user=mysql --log-error=/usr/local/mysql/data/localhost.err --pid-file=/usr/local/mysql/data/localhost.pid --socket=/tmp/mysql.sock --port=3306 root 2548 2180 0 11:37 pts/0 00:00:00 grep mysql
/etc/init.d/mysqld是一個(gè)shell啟動(dòng)腳本,啟動(dòng)后最終會(huì)調(diào)用mysqld_safe腳本,最后調(diào)用myslqd服務(wù)啟動(dòng)mysql,如下/etc/init.d/mysqld 腳本中調(diào)用mysqld_safe的程序$bindir/mysqld_safe --datadir="$datadir" --pid-file="$mysqld_pid_file_path" $other_args >/dev/null 2>&1 &
初始化數(shù)據(jù)庫(kù)時(shí),MySQL系統(tǒng)給的啟動(dòng)方法
mysqld_safe --user=mysql & 提示: 當(dāng)找回root密碼時(shí),會(huì)經(jīng)常使用mysqld_safe --user=mysql &帶參數(shù)啟動(dòng) 自己開(kāi)發(fā)的腳本啟動(dòng)數(shù)據(jù)庫(kù)時(shí)可能會(huì)用到這個(gè)啟動(dòng)方法 /etc/init.d/mysqld和mysqld_safe --user=mysql &的啟動(dòng)實(shí)質(zhì)是一樣的
關(guān)閉數(shù)據(jù)庫(kù)命令
[root@localhost init.d]# /etc/init.d/mysqld stop Shutting down MySQL. [確定] [root@localhost init.d]# netstat -tunpl |grep :3306 提示: 使用編譯及二進(jìn)制安裝的MySQL,mysqld啟動(dòng)腳本由support-files/mysql.server復(fù)制而來(lái)
強(qiáng)制關(guān)閉數(shù)據(jù)庫(kù)
killall mysqld pkill mysqld killall -9 mysqld 提示: 用killall關(guān)閉,直到出現(xiàn)mysqld:no process killed 表示完成關(guān)閉操作 盡量不要粗魯?shù)臍⑺罃?shù)據(jù)庫(kù)進(jìn)程,生成高并發(fā)環(huán)境可能引起數(shù)據(jù)庫(kù)數(shù)據(jù)丟失或者數(shù)據(jù)庫(kù)無(wú)法重新啟動(dòng)
優(yōu)雅關(guān)閉數(shù)據(jù)庫(kù)的方法
1. mysqlamin mysqladmin -uroot -paaaaaa shutdown 2. 自帶腳本 /etc/init.d/mysqld stop 3. kill信號(hào)的方法 kill -USER2 `cat /usr/local/mysql/data/mysql.pid`
命令行修改登錄提示符
mysql> prompt \u@rose \r:\m:\s> PROMPT set to '\u@rose \r:\m:\s>' root@rose 12:31:05>
上述修改提示符是臨時(shí)的,我們可以通過(guò)修改mysql的配置文件修改提示符
在my.cnf配置文件中[mysql]模塊下添加如下內(nèi)容(注意:不是[mysqld]),保存后無(wú)需重啟mysql,退出當(dāng)前session,重新登錄即可
[mysql] prompt=\\u@rose \\r:\\m:\\s>
退出MySQL客戶端我們使用quit
或者exit
或者ctrl+c