show databases; +--------------------+ | Database..."/>
您好,登錄后才能下訂單哦!
MySQL作為最常用的數(shù)據(jù)庫之一??偨Y(jié)一些常用命令便于日常使用。
一、關(guān)于庫的操作
1、查看數(shù)據(jù)庫
mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| sys |
| ty |
| womenscms3 |
+--------------------+
2、創(chuàng)建數(shù)據(jù)庫并設(shè)置字符編碼為utf8
mysql> create database test001 default character set utf8;
Query OK, 1 row affected (0.01 sec)
3、刪庫(慎重操作)
mysql> drop database womenscms3;
Query OK, 112 rows affected (3.94 sec)
4、用戶授權(quán)
mysql> grant select,insert,update,delete on *.* to 'root'@'%';
Query OK, 0 rows affected (0.01 sec)
5、查看用戶權(quán)限
mysql> show grants for root;
+-------------------------------------------+
| Grants for root@% |
+-------------------------------------------+
| GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' |
+-------------------------------------------+
1 row in set (0.00 sec)
mysql> select * from mysql.user where user='root'\G;
*************************** 1. row ***************************
Host: localhost
User: root
Select_priv: Y
Insert_priv: Y
Update_priv: Y
Delete_priv: Y
Create_priv: Y
Drop_priv: Y
Reload_priv: Y
Shutdown_priv: Y
Process_priv: Y
File_priv: Y
Grant_priv: Y
References_priv: Y
Index_priv: Y
Alter_priv: Y
Show_db_priv: Y
Super_priv: Y
Create_tmp_table_priv: Y
Lock_tables_priv: Y
Execute_priv: Y
Repl_slave_priv: Y
Repl_client_priv: Y
Create_view_priv: Y
Show_view_priv: Y
Create_routine_priv: Y
Alter_routine_priv: Y
Create_user_priv: Y
Event_priv: Y
Trigger_priv: Y
Create_tablespace_priv: Y
ssl_type:
ssl_cipher:
x509_issuer:
x509_subject:
max_questions: 0
max_updates: 0
max_connections: 0
max_user_connections: 0
plugin: mysql_native_password
authentication_string: *F846B31F10DD4389C384272E70B9BBA3AD9E1F94
password_expired: N
password_last_changed: 2019-06-24 18:10:54
password_lifetime: NULL
account_locked: N
常用命令
create database name; 創(chuàng)建數(shù)據(jù)庫
use databasename; 選擇數(shù)據(jù)庫
drop database name; 直接刪除數(shù)據(jù)庫,不提醒
show tables; 顯示表
describe tablename; 表的詳細(xì)描述
select 中加上distinct去除重復(fù)字段
顯示當(dāng)前mysql版本和當(dāng)前日期
select version(),current_date;
修改mysql中root的密碼:
shell>mysql -u root -p
mysql> update user set password=password(“root123″) where user=’root’;
mysql> flush privileges 刷新權(quán)限
mysql>use dbname; 打開數(shù)據(jù)庫
mysql>show databases; 顯示所有數(shù)據(jù)庫
mysql>show tables; 顯示數(shù)據(jù)庫mysql中所有的表
mysql>desc user; 顯示表mysql數(shù)據(jù)庫中user表的列信息)
grant
創(chuàng)建一個可以從任何地方連接到服務(wù)器的一個超管賬戶,必須分配一個密碼
mysql> grant all privileges on *.* to 'user_name'@'localhost' identified by 'password' ;
格式:grant select on 數(shù)據(jù)庫.* to 用戶名@登錄主機(jī) identified by “密碼”
刪除授權(quán):
mysql> revoke all privileges on *.* from root@”%”;
mysql> delete from user where user=”root” and host=”%”;
mysql> flush privileges;
重命名表:
mysql > alter table t1 rename t2;
備份:
mysqldump -hhostname -uusername -ppassword databasename > backup.sql;
恢復(fù):
mysql -hhostname -uusername -ppassword databasename< backup.sql;
附錄
mysql文件分布
/etc/rc.d/init.d/mysqld:MySQL服務(wù)器啟動腳本
/usr/bin/mysqlshow:顯示數(shù)據(jù)庫、表和列信息
/usr/libexec/mysqld:服務(wù)器的進(jìn)程程序文件
/usr/libexec/mysqlmanager:實(shí)例管理程序文件
/usr/share/doc/:存放說明文件的目錄
/usr/share/man/man 1/......:存放手冊頁的目m錄
/var/lib/mysql/:服務(wù)器數(shù)據(jù)庫文件存儲目錄
/var/log/mysqld.log:MySQL服務(wù)器的日志文件
免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進(jìn)行舉報,并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。