Ubuntu的web服務器搭建系列之MySQL(JDK+Tomcat+MySQL+Nginx+Redis+NodeJS)

1. 安裝mysql

apt-get update
apt-get install mysql-server

2. 檢測mysql是否運行

service mysql status
# mysql 啓動和中止
service mysql stop
service mysql start
service mysql restart

3. 控制檯root用戶登陸mysql

mysql -u root -p

4. 修改管理員密碼

mysqladmin -u root password newpassword

5. 遠程訪問mysql

默認狀況下,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

6. 用戶增刪改

# 受權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";

7. MySQL安裝後的目錄結構(只針對於使用apt-get install在線安裝狀況):

數據庫存放目錄: /var/lib/mysql/
相關配置文件存放目錄: /usr/share/mysql
相關命令存放目錄: /usr/bin(mysqladmin mysqldump等命令)
啓動腳步存放目錄: /etc/rc.d/init.d/vim

相關文章
相關標籤/搜索