mysql 常用的一些命令總結 -

MySQL 數據庫常用命令 


MySQL常用命令

1MySQL常用命令

create database name; 創建數據庫

use databasename; 選擇數據庫

drop database name 直接刪除數據庫,不提醒

show tables; 顯示錶

describe tablename; 表的詳細描述

select 中加上distinct去除重複字段

mysqladmin drop databasename 刪除數據庫前,有提示

顯示當前mysql版本和當前日期

select version(),current_date;

2、修改mysqlroot的密碼:

shell>mysql -u root -p

mysql> update user set password=password(”xueok654123″) where user=’root’;

mysql> flush privileges //刷新數據庫

mysql>use dbname 打開數據庫:

mysql>show databases; 顯示所有數據庫

mysql>show tables; 顯示數據庫mysql中所有的表:先use mysql;然後

mysql>describe user; 顯示錶mysql數據庫中user表的列信息);

3grant

創建一個可以從任何地方連接服務器的一個完全的超級用戶,但是必須使用一個口令something做這個

mysql> grant all privileges on *.* to user@localhost identified by ’something’ with

增加新用戶

格式:grant select on 數據庫.* to 用戶名@登錄主機 identified by “密碼

GRANT ALL PRIVILEGES ON *.* TO monty@localhost IDENTIFIED BY ’something’ WITH GRANT OPTION;

GRANT ALL PRIVILEGES ON *.* TO monty@”%” IDENTIFIED BY ’something’ WITH GRANT OPTION;

刪除授權:

mysql> revoke all privileges on *.* from root@”%”;

mysql> delete from user where user=”root” and host=”%”;

mysql> flush privileges;

創建一個用戶custom在特定客戶端it363.com登錄,可訪問特定數據庫fangchandb

mysql >grant select, insert, update, delete, create,drop on fangchandb.* to custom@ it363.com identified by ‘ passwd’

重命名錶:

mysql > alter table t1 rename t2;

4mysqldump

備份數據庫

shell> mysqldump -h host -u root -p dbname >dbname_backup.sql

恢復數據庫

shell> mysqladmin -h myhost -u root -p create dbname

shell> mysqldump -h host -u root -p dbname < dbname_backup.sql

如果只想卸出建表指令,則命令如下:

shell> mysqladmin -u root -p -d databasename > a.sql

如果只想卸出插入數據的sql命令而不需要建表命令,則命令如下:

shell> mysqladmin -u root -p -t databasename > a.sql

那麼如果我只想要數據,而不想要什麼sql命令時,應該如何操作呢?

   mysqldump -T./ phptest driver

其中,只有指定了-T參數纔可以卸出純文本文件,表示卸出數據的目錄./表示當前目錄,即與mysqldump同一目錄。如果不指定driver 表,則將卸出整個數據庫的數據。每個表會生成兩個文件,一個.sql文件,包含建表執行。另一個爲.txt文件,只包含數據,且沒有sql指令。

5、可將查詢存儲在一個文件中並告訴mysql從文件中讀取查詢而不是等待鍵盤輸入。可利用外殼程序鍵入重定向實用程序來完成這項工作。例如,如果在文件my_file.sql 中存放有查

詢,可如下執行這些查詢:

例如,如果您想將建表語句提前寫在sql.txt:

mysql > mysql -h myhost -u root -p database < sql.txt

  6:關於mysql的啓動問題

To start mysqld at boot time you have to copy

support-files/mysql.server to the right place for your system

 

PLEASE REMEMBER TO SET A PASSWORD FOR THE MySQL root USER !

To do so, start the server, then issue the following commands:

 

./bin/mysqladmin -u root password 'new-password'

./bin/mysqladmin -u root -h node1 password 'new-password'

 

Alternatively you can run:

./bin/mysql_secure_installation

 

which will also give you the option of removing the test

databases and anonymous user created by default.  This is

strongly recommended for production servers.

 

See the manual for more instructions.

 

You can start the MySQL daemon with:

cd . ; ./bin/mysqld_safe &

 

You can test the MySQL daemon with mysql-test-run.pl

cd ./mysql-test ; perl mysql-test-run.pl

 

關於數據庫方面的知識比較瑣碎,需要我們不斷的動手去實踐 去總結 去積累 不過最重要的基本的命令還是記牢爲好

省事省時 高效爲準!!!。。。。鑑於時間有限只能先到這了。。

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章