yum安裝MySQL並設置密碼 Shell代碼 yum install mysql yum install mysql-server yum install mysql-devel chgrp -R mysql /var/lib/mysql chmod -R 770 /var/lib/mysql service mysqld start mysql SET PASSWORD FOR 'root'@'localhost' = PASSWORD('secret_password'); 設置默認編碼等一些初始參數(my.cnf)(若無my.cnf, 則可cp /usr/share/mysql/my-small.cnf /etc/my.cnf) vi /etc/my.cnf [mysqld] datadir=/var/lib/mysql socket=/var/lib/mysql/mysql.sock user=mysql default-character-set=utf8 [添加] default-storage-engine=INNODB [添加] old_passwords=1 [client] default-character-set=utf8 [添加] [mysqld_safe] log-error=/var/log/mysqld.log pid-file=/var/run/mysqld/mysqld.pid 下面就是常規的操作了: 更改 root 密碼: mysqladmin -u root password 'newpassword' 添加mysql用戶: GRANT ALL PRIVILEGES ON my_db.* TO 'user'@'localhost' IDENTIFIED BY'password'; 刪除test數據庫: mysql -u root -p mysql> DROP DATABASE test; 刪除匿名帳戶: DELETE FROM mysql.user WHERE user = ''; 重載權限: mysql> FLUSH PRIVILEGES; 如要其他機器能訪問,在mysql.user中添加一個Host為'%'的user,然後flush priviledges;,最後防火牆加一句類似這樣的語句即可(開通3306端口): Shell代碼 -A RH-Firewall-1-INPUT -m state --state NEW -m tcp -p tcp --dport 3306 -j ACCEPT 如果要reboot自啟動: Shell代碼 chkconfig --levels 345 mysqld on