centos下mysql 命令_CentOS下mysql数据库常用命令总结
### 1.更改root密碼
`mysqladmin -uroot password 'yourpassword'`
### 2.遠(yuǎn)程登陸mysql服務(wù)器
`mysql -uroot -p -h192.168.137.10 -P3306`
### 3.查詢數(shù)據(jù)庫(kù)
`show databases;`
### 4.進(jìn)入某個(gè)數(shù)據(jù)庫(kù)
`use databasename;`
### 5.列出數(shù)據(jù)庫(kù)中的表
`show tables;`
### 6.查看某個(gè)表全部字段
`desc slow_log;`
`show create table slow_log\G; (不僅可以顯示表信息,還可以顯示建表語(yǔ)句)`
### 7.查看當(dāng)前用戶
`select user();`
### 8.查看當(dāng)前所在數(shù)據(jù)庫(kù)
`select database();`
### 9.創(chuàng)建新數(shù)據(jù)庫(kù)(可以指定字符集)
`create database db1 charset utf8;`
### 10.創(chuàng)建新表
`create table t1 (`id` int(4), `name` char(40));`
### 11.查看數(shù)據(jù)庫(kù)版本
`select version();`
### 12.查看數(shù)據(jù)庫(kù)狀態(tài)
```
show status; 當(dāng)前會(huì)話狀態(tài)
show global status; 全局?jǐn)?shù)據(jù)庫(kù)狀態(tài)
show slave status\G; 查看主從數(shù)據(jù)庫(kù)狀態(tài)信息
```
### 13.查詢數(shù)據(jù)庫(kù)參數(shù)
`show variables;`
### 14.修改數(shù)據(jù)庫(kù)參數(shù)
```
show variables like 'max_connect%';
set global max_connect_errors = 1000;(重啟數(shù)據(jù)庫(kù)會(huì)失效,要在配置文件中修改)
```
### 15.查看當(dāng)前數(shù)據(jù)庫(kù)隊(duì)列
`show processlist;`
### 16.創(chuàng)建普通用戶并授權(quán)給某個(gè)數(shù)據(jù)庫(kù)
`grant all on databasename.* to 'user1'@'localhost' identified by '123456';`
### 17.查詢表數(shù)據(jù)
```
select * from mysql.db; //查詢?cè)摫碇械乃凶侄?/p>
select count(*) from mysql.user; //count(*)表示表中有多少行
select db,user from mysql.db; //查詢表中的多個(gè)字段
select * from mysql.db where host like '10.0.%';在查詢語(yǔ)句中可以使用萬(wàn)能匹配 “%”
```
### 18.插入一行數(shù)據(jù)
`insert into db1.t1 values (1, 'abc');`
### 19.更改表的某一行數(shù)據(jù)
`update db1.t1 set name='aaa' where id=1;`
### 20.清空表數(shù)據(jù)
`truncate table db1.t1;`
### 21.刪除表
`drop table db1.t1;`
### 22.清空數(shù)據(jù)庫(kù)中的所有表(數(shù)據(jù)庫(kù)名是eab12)
```
mysql -N -s information_schema -e "SELECT CONCAT('TRUNCATE TABLE ',TABLE_NAME,';') FROM TABLES WHERE TABLE_SCHEMA='eab12'" | mysql -f eab12
```
### 23.刪除數(shù)據(jù)庫(kù)
`drop database db1;`
### 24.數(shù)據(jù)庫(kù)備份
`mysqldump -uroot -p'yourpassword' mysql >/tmp/mysql.sql`
### 25.數(shù)據(jù)庫(kù)恢復(fù)
`mysql -uroot -p'yourpassword' mysql
總結(jié)
以上是生活随笔為你收集整理的centos下mysql 命令_CentOS下mysql数据库常用命令总结的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: python定义数列每项的变量__Pyt
- 下一篇: linux cmake编译源码,linu