mysql日常使用的命令

來源:互聯網
上載者:User

mysql資料庫使用總結

本文主要記錄一些mysql日常使用的命令,供以後查詢。

1.更改root密碼

mysqladmin -uroot password 'yourpassword'

2.遠程登陸mysql伺服器

mysql -uroot -p -hip -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.Database Backup

mysqldump -uroot -p'yourpassword' mysql >/tmp/mysql.sql

25.資料庫恢複

mysql -uroot -p'yourpassword' mysql </tmp/mysql.sql

26.建立普通使用者

CREATE USER name IDENTIFIED BY 'ssapdrow';

27.更改普通使用者密碼

SET PASSWORD FOR name=PASSWORD('fdddfd');

28.查看name使用者權限

SHOW GRANTS FOR name;

29.資料庫遠程備份(匯出)

mysqldump -uroot -p'yourpassword' -hip mysql >/tmp/mysql.sql

30.資料庫恢複(匯入)

source /temp/mysql.sql

URL: http://www.cnblogs.com/jtnote/p/6233611.html

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.