騰訊雲CentOS伺服器操作mysql的一些常用命令
mysql -uroot -p 進入mysql systemctl status mysqld.service 檢視mysql狀態 systemctl stop mysqld.service 關閉mysql systemctl start mysqld.service開啟mysql
檢視伺服器的日誌 首先先進入tomcat下面的logs 執行此命令 tailf catalina.out 效果跟eclipse的控制檯類似
1.更改root密碼 mysqladmin -uroot password ‘yourpassword’ 2.遠端登陸mysql伺服器 mysql -uroot -p -h192.168.137.10 -P3306 3.查詢資料庫 show databases; 4.進入某個資料庫 use databasename; 5.列出資料庫中的表 show tables; 6.檢視某個表全部欄位 desc slow_log; show create table slow_log\G; (不僅可以顯示錶資訊,還可以顯示建表語句) 7.檢視當前使用者 select user(); 8.檢視當前所在資料庫 select database(); 9.建立新資料庫(可以指定字符集) create database db1 charset utf8; 10.建立新表 create table t1 (id int(4), name char(40)); 11.檢視資料庫版本 select version(); 12.檢視資料庫狀態 show status; 當前會話狀態 show global status; 全域性資料庫狀態 show slave status\G; 檢視主從資料庫狀態資訊 13.查詢資料庫引數 show variables; 14.修改資料庫引數 show variables like ‘max_connect%’; set global max_connect_errors = 1000;(重啟資料庫會失效,要在配置檔案中修改) 15.檢視當前資料庫佇列 show processlist; 16.建立普通使用者並授權給某個資料庫 grant all on databasename.* to ‘user1’@’localhost’ identified by ‘123456’; 17.查詢表資料 select * from mysql.db; //查詢該表中的所有欄位 select count() from mysql.user; //count()表示表中有多少行 select db,user from mysql.db; //查詢表中的多個欄位 select * from mysql.db where host like ‘10.0.%’;在查詢語句中可以使用萬能匹配 “%” 18.插入一行資料 insert into db1.t1 values (1, ‘abc’); 19.更改表的某一行資料 update db1.t1 set name=’aaa’ where id=1; 20.清空表資料 truncate table db1.t1; 21.刪除表 drop table db1.t1; 22.清空資料庫中的所有表(資料庫名是eab12) mysql -N -s information_schema -e “SELECT CONCAT(‘TRUNCATE TABLE ‘,TABLE_NAME,’;’) FROM TABLES WHERE TABLE_SCHEMA=’eab12’” | mysql -f eab12 23.刪除資料庫 drop database db1; 24.資料庫備份 mysqldump -uroot -p’yourpassword’ mysql >/tmp/mysql.sql 25.資料庫恢復 mysql -uroot -p’yourpassword’ mysql 26.新建普通使用者 CREATE USER name IDENTIFIED BY ‘ssapdrow’; 27.更改普通使用者密碼 SET PASSWORD FOR name=PASSWORD(‘fdddfd’); 28.檢視name使用者許可權 SHOW GRANTS FOR name; 29.指令碼中執行mysql命令 mysql -uuser -ppasswd -e”show databases” echo “show databases”|mysql -uuser -ppassword