您好,登錄后才能下訂單哦!
1、mysqld
啟動(dòng)mysql服務(wù)器: ./mysqld --defaults-file=/etc/my.cnf --user=root 客戶端連接: mysql --defaults-file=/etc/my.cnf 或 mysql -S /tmp/mysql.sock
2、mysqld_safe
啟動(dòng)mysql服務(wù)器: ./mysqld_safe --defaults-file=/etc/my.cnf --user=root & 客戶端連接: mysql --defaults-file=/etc/my.cnf 或 mysql -S /tm/mysql.sock
3、mysql.server
cp -v /usr/local/mysql/support-files/mysql.server /etc/init.d/ chkconfig --add mysql.server 啟動(dòng)mysql服務(wù)器:service mysql.server {start|stop|restart|reload|force-reload|status} 客戶端連接: 同1、2
4、mysqld_multi
mkdir $MYSQL_BASE/data2 cat <<-EOF>> /etc/my.cnf [mysqld_multi] mysqld = /usr/local/mysql/bin/mysqld_safe mysqladmin = /user/local/mysql/bin/mysqladmin user = mysqladmin password = mysqladmin [mysqld3306] port = 3306 socket = /tmp/mysql3306.sock pid-file = /tmp/mysql3306.pid skip-external-locking key_buffer_size = 16M max_allowed_packet = 1M table_open_cache = 64 sort_buffer_size = 512K net_buffer_length = 8K read_buffer_size = 256K read_rnd_buffer_size = 512K myisam_sort_buffer_size = 8M basedir = /usr/local/mysql datadir = /usr/local/mysql/data [mysqld3307] port = 3307 socket = /tmp/mysql3307.sock pid-file = /tmp/mysql3307.pid skip-external-locking key_buffer_size = 16M max_allowed_packet = 1M table_open_cache = 64 sort_buffer_size = 512K net_buffer_length = 8K read_buffer_size = 256K read_rnd_buffer_size = 512K myisam_sort_buffer_size = 8M basedir = /usr/local/mysql datadir = /usr/local/mysql/data2 EOF #mysql -S /tmp/mysql3306.sock mysql>GRANT SHUTDOWN ON *.* TO 'mysqladmin'@'localhost' identified by 'mysqladmin' with grant option; #mysql -S /tmp/mysql3307.sock mysql>GRANT SHUTDOWN ON *.* TO 'mysqladmin'@'localhost' identified by 'mysqladmin' with grant option; 啟動(dòng)mysql服務(wù)器:./mysqld_multi --defaults-file=/etc/my.cnf start 3306-3307 關(guān)閉mysql服務(wù)器:mysqladmin shutdown
1. windows下:
啟動(dòng): mysqld --console 或 net start mysql 關(guān)閉: mysqladmin -u root shutdown 或 net stop mysql
linux下:
啟動(dòng): service mysql start 停止: service mysql stop 重啟服務(wù): service mysql restart
1. 新建用戶: 創(chuàng)建一個(gè)名為: buff,密碼為: buff的用戶
// root 用戶登陸 MySQL mysql -uroot -p Enter password: // 新建用戶 mysql>insert into mysql.user(Host,User,Password) values("localhost","buff",password("buff")); // 刷新系統(tǒng)權(quán)限表 mysql>flush privileges;
登錄測試
mysql>exit // 用戶 buff 登陸 MySQL mysql -ubuff -p Enter password: mysql> // 說明新建的用戶buff登錄成功
用戶授權(quán)
// root 用戶登陸 MySQL mysql -uroot -p Enter password: // 為用戶 buff 創(chuàng)建一個(gè)數(shù)據(jù)庫 bluebuff mysql>create database bluebuff; // 授權(quán)用戶 buff 擁有數(shù)據(jù)庫 bluebuff 的所有權(quán)限 mysql>grant all privileges on bluebuff.* to buff@localhost identified by 'buff'; mysql>flush privileges;
登錄測試
// 用戶 buff 登陸數(shù)據(jù)庫 mysql -ubuff -p Enter privileges: // 顯示數(shù)據(jù)庫 mysql>show databases;
結(jié)果如下圖所示,說明為用戶 buff 授權(quán)成功
5、 修改用戶 buff 的密碼
// root 用戶登陸 MySQL mysql -uroot -p Enter password: // 修改用戶 buff 的密碼 mysql>update table mysql.user set password=password('buffer') where User='buff' and Host='localhost'; mysql>flush privileges;
6、 刪除用戶
// root 用戶登陸 MySQL mysql -uroot -p Enter password: // 刪除用戶 buff mysql>delete from mysql.user where User = 'buff' and Host = 'localhost'; mysql>flush privileges;
7、 刪除數(shù)據(jù)庫
mysql>drop database bluebuff;
在mysql中,授予用戶的權(quán)限可能分全局層級權(quán)限、數(shù)據(jù)庫層級權(quán)限、表層級別權(quán)限、列層級別權(quán)限、子程序?qū)蛹墮?quán)限
1. 全局層級:
全局權(quán)限適用于一個(gè)給定服務(wù)器中的所有數(shù)據(jù)庫。這些權(quán)限存儲在mysql.user表中。GRANT ALL ON *.*和REVOKE ALL ON *.*只授予和撤銷全局權(quán)限。 例:a. 創(chuàng)建一個(gè)測試賬號test,授予全局層級的權(quán)限 mysql> grant select,insert on *.* to test@'%' identified by 'test'; mysql> flush privileges; b. 查詢授予test的權(quán)限 show grants for test; select * from mysql.user where user='test'\G;
2 、 數(shù)據(jù)庫層級:
數(shù)據(jù)庫權(quán)限適用于一個(gè)給定數(shù)據(jù)庫中的所有目標(biāo)。這些權(quán)限存儲在mysql.db和mysql.host表中。GRANT ALL ON db_name.*和REVOKE ALL ON db_name.*只授予和撤銷數(shù)據(jù)庫權(quán)限 例:a. 創(chuàng)建一個(gè)測試賬號test,授予數(shù)據(jù)庫層級的權(quán)限 drop user test; grant select,insert,update,delete on MyDB.* to test@'%' identified by 'test'; b. 查詢授予test的權(quán)限 select * from mysql.user where user='test'\G; --可以看到無任何授權(quán) select * from mysql.db where user='test'\G; show grants for test;
3、 表層級:
表權(quán)限適用于一個(gè)給定表中的所有列。這些權(quán)限存儲在mysql.tables_priv表中。GRANT ALL ON db_name.tbl_name和REVOKE ALL ON db_name.tbl_name只授予和撤銷表權(quán)限。 例:a. 創(chuàng)建一個(gè)測試賬號test,授予表層級的權(quán)限 drop user test; flush privileges; grant all on MyDB.kkk to test@'%' identified by 'test'; b. 查詢授予test的權(quán)限 show grants for test; select * from mysql.tables_priv\G;
4、 列層級:
列權(quán)限適用于一個(gè)給定表中的單一列。這些權(quán)限存儲在mysql.columns_priv表中。當(dāng)使用REVOKE時(shí),您必須指定與被授權(quán)列相同的列。 例:a. 創(chuàng)建一個(gè)測試賬號test,授予列層級的權(quán)限 drop user test; flush privileges; grant select (id, col1) on MyDB.TEST1 to test@'%' identified by 'test'; flush privileges; b. 查詢授予test的權(quán)限 select * from mysql.columns_priv; show grants for test;
5、 子程序?qū)蛹墸?/strong>
CREATE ROUTINE, ALTER ROUTINE, EXECUTE和GRANT權(quán)限適用于已存儲的子程序。這些權(quán)限可以被授予為全局層級和數(shù)據(jù)庫層級。而且,除了CREATE ROUTINE外,這些權(quán)限可以被授予為子程序?qū)蛹墸⒋鎯υ趍ysql.procs_priv表中。 例:a. 創(chuàng)建一個(gè)測試賬號test,授予子程序?qū)蛹壍臋?quán)限 DROP PROCEDURE IF EXISTS PRC_TEST; DELIMITER // CREATE PROCEDURE PRC_TEST() -> BEGIN -> SELECT * FROM kkk; -> END // DELIMITER ; grant execute on MyDB.PRC_TEST to test@'%' identified by 'test'; flush privileges; b. 查詢授予test的權(quán)限 show grants for test; select * from mysql.procs_priv where User='test';
總結(jié):
1. 如果需要查看用戶被授予的權(quán)限,就需要從這五個(gè)層級來查看被授予的權(quán)限。從上到下或從小到上,逐一檢查各個(gè)層級被授予的權(quán)限。
2. grant create routine, alter routine, select, create, insert, update, delete, execute on ….
3. 如果客戶端無法連接到服務(wù)器,則查看user表中的host項(xiàng)是否為'%',并且已經(jīng)授權(quán)了
免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。