Linux系統中MySQL的常用操作命令

來源:互聯網
上載者:User

標籤:sql資料庫   檔案   ref   etc   config   啟動   環境   profile   art   

服務:

# chkconfig --list        列出所有系統服務
# chkconfig --list | grep on     列出所有啟動的系統服務

# chkconfig --list mysqld

# whereis mysql  查看檔案安裝路徑
# which mysql     查詢運行檔案所在路徑(檔案夾地址)
usr/bin/mysql 是指:mysql的運行路徑
var/lib/mysql 是指:mysql資料庫檔案的存放路徑
usr/lib/mysql 是指:mysql的安裝路徑

添加環境變數:

# vi /etc/profile
# export MYSQL_HOME=/usr/local/mysql
# export PATH=$PATH:$MYSQL_HOME/bin

1.資料庫指令:

# service mysqld start    啟動MySQL
# service mysqld restart 重啟MySQL
# service mysqld stop     停止MySQL

2.進入MySQL表單操作

# -u root -p  /mysql -h localhost -u root -p DatabaseName;    進入MySQL
 MySQL> show databases;            列出資料庫
 MySQL>  create database XXX;      建立資料庫XXX

 MySQL>  use databaseName;         使用資料庫databaseName
 MySQL>  show tables;              列出表單

MySQL> create table mytablename (ID int auto_increment not null primary key,usename varchar(20),password varchar(64),sex varchar(10),address varchar(20));  建立表單
MySQL> drop table mytablename ;                 刪除表單
MySQL> drop database databasename;              刪除資料庫

3.增刪改查

MySQL>  insert into mytablename values(‘‘,‘zhangsan‘,‘123456‘,‘fomale‘,‘guiyanag‘);  插入

MySQL> select * from mytablename ;                 尋找驗證結果
MySQL> select * from mytablename  where ID = ‘1‘;  精準尋找

MySQL> update mytablename  set address = ‘shanghai‘ where username = ‘zhangsan‘; 修改zhangsan的address為shanghai

MySQL> delete from mytablename  where ID = ‘1‘;     刪除記錄

新增萬能使用者

  grant select On database.* to [email protected] identity by ‘password‘

使用者名稱user_1 密碼是123456

可以自任何PC上登入這個使用者對資料庫操作

MySQL> grant select,insert update,delete on *.* to [email protected]"%" identity by "123456";

建立只有在本機才能操作資料庫的使用者

使用者名稱user_2 密碼是123456

MySQL> grant select,insert update,delete on *.* to [email protected] identity by "123456";

登入資料庫庫

MySQL> -u user_1 -p -h IP地址;

另外附上常用的一些命令我列一下僅供參考:

其它的mysql資料庫相關的操作如下 

(1) 建立資料庫TestDB mysql> create database TestDB; 
(2) 制定TestDB資料庫為當前預設資料庫 mysql> use TestDB; 
(3) 在TestDB資料庫中建立表customers mysql> create table customers(userid int not null, username varchar(20) not null); 
(4) 顯示資料庫列表 mysql> show databases; 
(5)顯示資料庫中的表 mysql> show tables; 
(6)刪除表customers mysql> drop table customers; 
(7)顯示customers表的結構 mysql> desc customers; 
(8) 向customers表中插入一條記錄 mysql> insert into customers(userid, username) values(1, ‘hujiahui‘); 
(9) 讓操作及時生效; mysql> commit; 
(10) 查詢customers中的記錄 mysql> select * from customers; 
(11) 更新表中的資料 mysql> update customers set username=‘DennisHu‘ where userid=1; 
(12) 刪除表中的記錄 mysql> delete from customers; 
(13)授予likui使用者訪問資料庫的許可權 # grant select, insert, update, delete on *.* to [email protected] indentified by "123456";

Linux系統中MySQL的常用操作命令

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.