Linux操作系統(tǒng)操作MySQL常用命令小結
更新時間:2017年07月13日 14:20:42 作者:medisons
本文給大家分享Linux操作系統(tǒng)操作MySQL常用命令小結,需要的朋友參考下吧
下面給大家分享mysql常用命令,
-- 啟動數據庫 service myslqd start; -- 進入MySQL -u root -p/mysql -h localhost -u root -p DatabaseName; -- 列出數據庫 show database; -- 創(chuàng)建數據庫 create database XXXX; -- 選擇數據庫 use DatabaseName; -- 羅列表 show table; -- 顯示表格的屬性 show columns from tablename; -- 建立數據庫 source filename.txt; -- 增加一個字段 alter table tablename add column filename datatype; -- 增加多個字段 alter table tablename add column filename1 datatype,add column filename2 datatype; -- 新增一個用戶 grant all On *.* to user@localhost identity by "password"; -- 查詢時間 select now(); -- 查詢用戶 select user(); -- 查詢數據庫版本 select version(); -- 查詢當前使用的數據庫 select database(); -- 刪除student_course數據庫中的student數據便 rm -f student_cource/student.* -- 備份數據庫(備份數據庫Apple1) MySQLdump -u root -p Apple1>C:\Apple1.txt -- 備份表(將數據庫Apple1中的mytable表備份) MySQLdump -u root -p mytable>C:\Apple.txt -- 創(chuàng)建臨時表(mytable) create temporary table mytable(id int,address varchar(20),name varchar(20)); -- 創(chuàng)建表前先判斷系統(tǒng)是否存在這個表 create table if not exists mytable(......); -- 從已有的table1表中復制表結構到table2 create table table2 select * from table1 where 1<>1; -- 復制表 create table table2 select * from table1; -- 重命名表名 alter table table1 rename as table2; -- 修改列的數據類型 alter table table1 modify ID int unsigned;--把列ID的類型修改為int unsigned alter table table1 change ID SID int unsigned; --把列ID改名為 SID且類型改為int unsigned -- 創(chuàng)建索引 alter table table1 add index Ind_id (ID); create index ind_ID on tablename (ID); create unique index ind_id on tablename(ID); -- 刪除索引 drop index ind_id On table1; alter table table1 drop index ind_ID; -- 聯(lián)合查詢字符與多個列連接‘ select concat(ID,':',name,'=') from table1 -----------------------第二片------------------------------------ --顯示數據庫 show database; --顯示數據庫中的表 show tables; --顯示數據表結構 describe tablename; --顯示表記錄 select * from tablename; --查詢能操作MySQL的用戶 select * from user; --創(chuàng)建數據庫 create database databasename --例如↓ MySQL> create database AA; ---創(chuàng)建表 user AA; mysql> create table table1(ID int auto_increment not null primary key,name char(6),sex char(6),birthday date) ---插入幾條記錄 MySQL> insert into AA values('','張三','男','1971-10-01'); MySQL> insert into AA values('','劉佳佳','女','1978-10-01'); --驗證結果 MySQL> select * from AA; --修改張三的生日為1971-01-10 MySQL> update AA set birthday = '1971-01-10' where ID = '1'; --刪除記錄 MySQL> delete from AA where ID = '1'; --刪除表以及庫 mysql> drop table tablename; MySQL> drop database databasename; --新增萬能用戶 -- 格式:grant select On database.* to username@localhost identity by 'password' 用戶名user_1 密碼是123456 --可以自任何PC上登錄這個用戶對數據庫為所欲為 MySQL> grant select,insert update,delete on *.* to user_1@"%" identity by "123456"; --創(chuàng)建只有在本機才能操作數據庫的用戶 用戶名user_2 密碼是123456 MySQL> grant select,insert update,delete on *.* to user_2@localhost identity by "123456"; --登錄數據庫庫 MySQL> -u user_1 -p -h IP地址;
以上所述是小編給大家介紹的Linux操作系統(tǒng)操作MySQL常用命令小結,希望對大家有所幫助,如果大家有任何疑問請給我留言,小編會及時回復大家的。在此也非常感謝大家對腳本之家網站的支持!
相關文章
mysql如果數據不存在,則插入新數據,否則更新的實現(xiàn)方法
mysql如果數據不存在,則插入新數據,否則更新的實現(xiàn)方法2011-11-11MYSQL多表聯(lián)查on和where的區(qū)別小結
在使用left join時過濾條件放到on后面還是where后面是有區(qū)別的,如果沒有搞清楚他們的區(qū)別,連表匯總的結果就會變少或者變多,本文就來詳細介紹一下兩者的區(qū)別,感興趣的可以了解一下2023-11-11Mysql學習之創(chuàng)建和操作數據庫及表DDL大全小白篇
本篇文章是MySQL小白入門篇,主要講解創(chuàng)建和操縱數據庫及表懂得了,內容非常全面,有需要的朋友可以借鑒參考下,希望可以有所幫助2021-09-09