在Linux上對資料庫操作常用命令
阿新 • • 發佈:2018-12-16
進入資料庫客戶端,作用命令mysql -u root -p 輸入密碼,預設為空
mysql資料庫使用總結
本文主要記錄一些mysql日常使用的命令,供以後查詢。
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
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(