mysql 的相關操作 MySQL相關操作知識

2021-10-18 21:03:46 字數 1643 閱讀 3066

1、解決客戶端聯不上mysql伺服器的問題:

grant all privileges on *.* to 'root'@'%' identified by '' with grant option;

flush privileges;

2、登陸mysql: mysql -u root -p 123456

3、檢視所有資料庫:show databases;  //注意s和分號

4、選擇資料庫:use 庫名

5、檢視當前選擇的資料庫:select database();  //注意分號

6、列出所選資料庫中所有表:show tables;  //注意s和分號

7、向表中插入資料:insert into 表名(欄位1,欄位2,...) value(值1,值2,...)

用例:insert into student(name,math,chinese) value('zhangsan',96,85)

8、刪除表中某條資料:delete from 表名 where 字段=值 [and 欄位2=值2]

用例:delete from ap_table where mac='aa:bb:cc:dd:12:34'

9、更新表中某條資料:updata 表名 set 欄位1=值1,[欄位2=值2,...] where 欄位n=值n [and 欄位n+1=值n+1]

用例:update sta_table set ip='172.16.31.56' where mac='11:22:33:ee:ff:04'

10、查詢表中的某條資料:select * from 表名 where 字段=值

用例:select * from sta_table where mac='aa-bb-cc-0f-22-5f'

注意: 增、刪、改、查的命令中,字串需要加單引或雙引;整數則不需要引號。

11、檢視表中所有資料: select * from 表名

用例:select * from sta_table

12、清除表中所有資料(沒有刪除表結構):

語法1:delete from 表名                        用例:delete from sta_table

語法2:truncate table 表名                    用例:truncate table sta_table

13、徹底刪除表,連同表結構也刪除:drop table 表名

14、檢視表結構:describe 表名

15、匯出資料庫:mysqldump -u 使用者名稱 -p --default-character-set=latin1 資料庫名 > 匯出的檔名

用例:mysqldump -u root -p --default-character-set=latin1 mydatabase > /home/ex_db.sql

16、匯入資料庫:進入資料庫,輸入source命令,如:

用例:source ex_db.sql

17、當忘記資料庫密碼或不設密碼時,如此操作:/usr/bin/mysqld_safe --skip-grant-tables &

執行效果如下:

然後按ctrl+c回到命令列。

mysql 的相關操作 mysql 相關操作

mysql u root p 回撤後輸入密碼 123456,進入mysql 資料庫簡單操作 1 建立資料庫 create database 資料庫名稱 2 檢視資料庫 show databases 3 刪除資料庫 drop database 資料庫名稱 4 開啟資料庫 use 資料庫名稱 資料表簡單...

mysql相關操作 mysql 相關操作

1 登入 mysql u root p 2 檢視當前有的資料庫 show databases 3 建立資料庫 create database 資料庫名 4 操作 使用 資料庫 use 資料庫名 5 檢視有哪些表 show tables 6 建立表 create table 表名 7 刪除表 drop...

mysql相關操作

1.遠端登入mysql mysql h ip u root p 密碼 2.建立使用者 格式 grant 許可權 on 資料庫.to 使用者名稱 登入主機 identified by 密碼 例1 增加乙個test1使用者,密碼為123456,可以在任何主機上登入,並對所有資料庫有查詢,增加,修改和刪除...