centos中操作mysql的基本常用命令

2021-08-30 03:45:36 字數 2422 閱讀 8038

1、mysql常用命令

create database name; 建立資料庫

use databasename; 選擇資料庫

drop database name 直接刪除資料庫,不提醒

show tables; 顯示表

describe tablename; 表的詳細描述

select 中加上distinct去除重複字段

mysqladmin drop databasename 刪除資料庫前,有提示。

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

select version(),current_date;

2、修改mysql中root的密碼:

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表的列資訊);

3、grant

建立乙個可以從任何地方連線伺服器的乙個完全的超級使用者,但是必須使用乙個口令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;

4、mysqldump

備份資料庫

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

CentOS中Mysql一些常用操作

安裝mysql yum y install mysql server 修改mysql配置 vi etc my.cnf 這裡會有很多需要注意的配置項,後面會有專門的筆記 暫時修改一下編碼 新增在密碼下方 default character set utf8 設定mysql隨系統啟動 chkconfig...

CentOS操作MySQL問題集錦

centos操作mysql問題 1,出現了問題 root rekfan mysql service mysql restart mysql server pid file could not be found 失敗 starting mysql.the server quit without upd...

CentOs 下mysql 相關操作

1 linux centos一般作為伺服器使用,因此,mysql伺服器應該隨機自啟動。檢視開機自啟動的服務使用chkconfig命令,如下 chkconfig list 或是只檢視mysql服務 chkconfig list mysqld 可以看到mysql的2 5為on,說明mysql服務會隨機器...