apt-get update
apt-get install mysql-server
複製代碼
service mysql status
# mysql 啓動和中止
service mysql stop
service mysql start
service mysql restart
複製代碼
mysql -u root -p
複製代碼
mysqladmin -u root password newpassword
複製代碼
默認狀況下,mysql佔用的3306端口只是在IP 127.0.0.1上監聽,拒絕了其餘IP的訪問(經過netstat能夠查看到。mysql
能夠修改/etc/mysql/mysql.conf.d/mysqld.cnf文件:sql
vim /etc/mysql/mysql.conf.d/mysqld.cnf
複製代碼
有如下內容數據庫
# bind-address = 127.0.0.1(註釋掉該行)
複製代碼
mysql -u root -p 123456 #登陸mysql
use mysql; #進入數據庫mysql
# 查看如今的用戶信息
SELECT DISTINCT CONCAT('User: ''',user,'''@''',host,''';') AS query FROM mysql.user;
delete from user where user=''; # 刪除匿名用戶
# 增長容許遠程訪問的用戶(給root授予在任意主機(%)訪問任意數據庫的全部權限)
grant all privileges on *.* to 'root'@'%' identified by '123456' with grant option;
# 若是不想增長記錄,只是想給已存在的用戶添加
update user set host='%' where user='root' and host='localhost';
# 刷新系統權限表
flush privileges;
# 退出數據庫
exit
複製代碼
# 受權sfs用戶擁有"school"數據庫的某些權限:
grant select,delete,update,create,drop on school.* to sfs@"%" identified by "123456";
# 刪除用戶sfs
DELETE FROM user WHERE User="sfs" and Host="localhost";
複製代碼
數據庫存放目錄: /var/lib/mysql/
相關配置文件存放目錄: /usr/share/mysql
相關命令存放目錄: /usr/bin(mysqladmin mysqldump等命令)
啓動腳步存放目錄: /etc/rc.d/init.d/vim