Linux運維常用的 MySQL基礎命令
MySQL基礎命令
-------------
創建MySQL庫,授權。
>create database mysqldb character set utf8;
>grant all privileges on mysqldb.* to ‘mysqluser[email protected] identified by ‘mysqlpasswd‘;
>flush privileges;
創建了mysqldb數據庫,創建mysqluser用戶,並授權mysqldb的所有權限。___________________________________________________________________________
設置遠程訪問MySQL
>grant all privileges on mysqldb.* to ‘mysqluser[email protected]%‘ identified by ‘mysqlpasswd‘;
# mysqluser是用戶名,%代表任意主機,‘mysqlpasswd‘指定的登錄密碼(這個和本地的密碼可以設置不同的,互不影響)
>flush privileges; # 重載系統權限
設置只允許192.168.1.2的主機用root用戶訪問MySQL
>grant all privileges on *.* to ‘root[email protected]
>flush privileges;
設置防火墻,讓 3306 端口對外可訪問
iptables -I INPUT -p tcp -m state --state NEW -m tcp --dport 3306 -j ACCEPT
iptables -nL
service iptables save
設置允許192.168.1.1/24 網段的所有主機用root用戶訪問MySQL
>grant all privileges on *.* to ‘root[email protected]