標籤:mysql
啟動 關閉
/etc/init.d/mysqld start
netstat -lntup | grep 3306
ps -ef | grep mysql | grep -v grep
root 1946 1 0 01:51 pts/1 00:00:00 /bin/sh /application/mysql/bin/mysqld_safe --datadir=/application/mysql/data --pid-file=/application/mysql/data/lnmp.com.pid
mysql 2187 1946 0 01:51 pts/1 00:00:00 /application/mysql/bin/mysqld --basedir=/application/mysql --datadir=/application/mysql/data --plugin-dir=/application/mysql/lib/plugin --user=mysql --log-error=/application/mysql/data/lnmp.com.err --pid-file=/application/mysql/data/lnmp.com.pid --socket=/tmp/mysql.sock --port=3306
vim /etc/init.d/mysqld //啟動過程
$bindir/mysqld_safe --datadir="$datadir" --pid-file="$mysqld_pid_file_path" $other_args >/d ev/null 2>&1 &
mysqld_safe --user=mysql & //初始化時給出的啟動方法
/etc/init.d/mysqld stop
ss -lnt | grep 3306
LISTEN 0 50 *:3306
killall mysqld pkill mysqld killall -9 mysqld //盡量不要粗魯的關閉資料庫
mysqladmin -uroot -p123456 shutdown
登陸
ifconfig //看是否是測試還是正式環境,,,備份資料庫
mysql
mysql -uroot -p
mysql> prompt \[email protected] \r:\m:\s-> //修改提示符
[email protected] 02:13:09->
[mysql]
prompt \[email protected] \r:\m:\s-> // /etc/my.cnf
協助
mysql> help
exit
密碼
mysqladmin -u root password‘123456‘ //最常用 簡單 實用
mysqladmin -u root -p‘123456‘ password ‘123123‘
select user,host,password from mysql.user;
mysql> update mysql.user set password=password(456) where user=‘root‘ and host=‘localhost‘; //要指定條件
mysql> set password=password(‘123123‘);
mysql> flush privileges;
找回mysql root使用者密碼
/etc/init.d/mysqld stop
mysqld_safe --skip-grant-tables --user=mysql & //忽略授權表如果是編譯的,預設是/usr/local/mysql 會有報錯。
sed -i ‘s#/usr/local/mysql#/application/mysql#g‘ /application/mysql/bin/mysqld_safe
update user set password=password(新密碼) where user=‘root‘ and host=‘localhost‘;==>設定新密碼
flush privileges;==>重新整理
新開視窗 mysqladmin -uroot -p shutdown ==>新密碼測試關掉資料庫,成功關閉就證明修改成功
//多執行個體要指定 mysqld_safe --defaults-file=/data/3306/my.cnf --skip-grant-tables
mysqld_safe --skip-grant-tables --skip-networking &
// skip-networking
開啟該選項後就不能遠端存取MySQL
為安全考慮希望指定的IP訪問MySQL,可以在設定檔中增加bind-address=IP,前提是關閉skip-networking
本文出自 “何全” 部落格,請務必保留此出處http://hequan.blog.51cto.com/5701886/1771935
mysql基礎操作