apt安裝
sudo apt install mysql-server
常用配置
參考:mysql配置文件
[mysqld]
basedir = /usr // 安裝目錄
socket = /usr/local/mysql/data/mysql.sock // mysql客戶端程序和服務器之間的本地通訊時使用的套接字文件
pid-file = /usr/local/mysql/data/mysql.pid // pid文件所在目錄
datadir = /var/lib/mysql // 數(shù)據(jù)文件存放的目錄
bind_address = 127.0.0.1 // 綁定的IP地址
port = 3306 // 監(jiān)聽端口號
skip-grant-tables = 1 // 跳過權(quán)限認證
常用管理命令
- mysql服務啟停
#啟動
sudo service mysql start
#停止
sudo service mysql stop
- 檢查服務狀態(tài)
systemctl status mysql.service
sudo service mysql status
- 新增用戶
create user "username"@"host" identified by "password";
//host="localhost"為本地登錄用戶,host="ip"為ip地址登錄览闰,host="%"為外網(wǎng)ip登錄
create user 'test'@'localhost' identified by 'test';
create user 'test'@'192.168.1.2' identified by 'test';
create user 'test'@'%' identified by 'test';
- 修改密碼
SET PASSWORD FOR 'root'@'localhost' = PASSWORD('123456');
- 刪除用戶
drop user 'username'@'host';
- 授權(quán)
grant privileges on databasename.tablename to 'username'@'host' IDENTIFIED BY 'PASSWORD';
/*授予用戶通過外網(wǎng)IP對于該數(shù)據(jù)庫的全部權(quán)限*/
grant all privileges on `test`.* to 'test'@'%' ;
/*授予用戶在本地服務器對該數(shù)據(jù)庫的全部權(quán)限*/
grant all privileges on `test`.* to 'test'@'localhost';
grant select on test.* to 'user'@'localhost'; /*給予查詢權(quán)限*/
grant insert on test.* to 'user'@'localhost'; /*添加插入權(quán)限*/
grant delete on test.* to 'user'@'localhost'; /*添加刪除權(quán)限*/
grant update on test.* to 'user'@'localhost'; /*添加權(quán)限*/
flush privileges; /*刷新權(quán)限*/
- 刪除權(quán)限
revoke privileges on databasename.tablename from 'username'@'host';
revoke delete on test.* from 'user'@'localhost';
- 查詢權(quán)限
show grants;