1.設定開機啟動 MySql
# chmod 755 /etc/rc.d/rc.mysqld
2.建立MySql 的基本資料庫
# mysql_install_db --user=mysql
3.改變權限
# chown -R mysql.mysql /var/lib/mysql
4.啟動MySql
# /etc/rc.d/rc.mysqld start
5.執行安全安裝的設定
# mysql_secure_installation NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MySQL SERVERS IN PRODUCTION USE! PLEASE READ EACH STEP CAREFULLY! In order to log into MySQL to secure it, we'll need the current password for the root user. If you've just installed MySQL, and you haven't set the root password yet, the password will be blank, so you should just press enter here. Enter current password for root (enter for none):
(預設 MySql的 root 登入密碼是空白的,所以直接按 Enter,跳過)OK, successfully used password, moving on... Setting the root password ensures that nobody can log into the MySQL root user without the proper authorisation. Set root password? [Y/n]Y
(為了安全起見,請建立一個 MySql的 root 登入密碼,輸入 Y)New password: Re-enter new password: Password updated successfully! Reloading privilege tables.. ... Success! By default, a MySQL installation has an anonymous user, allowing anyone to log into MySQL without having to have a user account created for them. This is intended only for testing, and to make the installation go a bit smoother. You should remove them before moving into a production environment. Remove anonymous users? [Y/n]Y
(為了安全起見,必須刪除匿名帳號,輸入 Y)... Success! Normally, root should only be allowed to connect from 'localhost'. This ensures that someone cannot guess at the root password from the network. Disallow root login remotely? [Y/n]Y
(為了安全起見,不允許從遠端登陸MySql,輸入 Y)... Success! By default, MySQL comes with a database named 'test' that anyone can access. This is also intended only for testing, and should be removed before moving into a production environment. Remove test database and access to it? [Y/n]Y
(為了安全起見,移除名為 test 的資料庫,輸入 Y)- Dropping test database... ... Success! - Removing privileges on test database... ... Success! Reloading the privilege tables will ensure that all changes made so far will take effect immediately. Reload privilege tables now? [Y/n]Y
(馬上讀取權限表,輸入 Y)Cleaning up... All done! If you've completed all of the above steps, your MySQL installation should now be secure. Thanks for using MySQL!
完成 MySQL 的安全設定