First, Completely Removing MySQL Server in CentOS
Step 1: Check list the mysql rpm which is installed on server
#rpm -qa | grep mysql
or
#yum list installed | grep mysql
Step 2 : Removing all mysql-related packages (with “yum remove”)
#yum remove mysql-client mysql-server mysql-common mysql-devel
Step 3: Delete the databases folder
#rm -rf /var/lib/mysql/
#rm -rf /etc/my.cnf
second,安装mysql 教程:
确保已经设置好hostname:
hostname
hostname -f
sudo yum update
Mysql必须安装社区版本:
wget http://repo.mysql.com/mysql-community-release-el7-5.noarch.rpm sudo rpm -ivh mysql-community-release-el7-5.noarch.rpm yum update
在安装的过程中,会提示你是否下载相应的文件,输入 y ok。
sudo yum install mysql-server
sudo systemctl start mysqld
Harden MySQL Server
-
Run the
mysql_secure_installation
script to address several security concerns in a default MySQL installation.1
sudo mysql_secure_installation
You will be given the choice to change the MySQL root password, remove anonymous user accounts, disable root logins outside of localhost, and remove test databases. It is recommended that you answer yes
to these options.
root 用户登录:
mysql -u root -p
输入上一步你输入的密码,出现:
mysql>
测试:
create database testdb;
create user 'testuser'@'localhost' identified by 'password';
grant all on testdb.* to 'testuser' identified by 'password';
退出mysql:
exit
Create a Sample Table
-
Log back in as
testuser
.1
mysql -u testuser -p
-
Create a sample table called customers. This creates a table with a customer ID field of the type INT for integer (auto-incremented for new records, used as the primary key), as well as two fields for storing the customer’s name.
1 2
use testdb; create table customers (customer_id INT NOT NULL AUTO_INCREMENT PRIMARY KEY, first_name TEXT, last_name TEXT);
-
Then exit MySQL.
1
exit
Reset the MySQL Root Password
If you forget your root MySQL password, it can be reset.
-
Stop the current MySQL server instance, then restart it with an option to not ask for a password.
1 2
sudo systemctl stop mysqld sudo mysqld_safe --skip-grant-tables &
-
Reconnect to the MySQL server with the MySQL root account.
1
mysql -u root
-
Use the following commands to reset root’s password. Replace
password
with a strong password.1 2 3 4
use mysql; update user SET PASSWORD=PASSWORD("password") WHERE USER='root'; flush privileges; exit
-
Then restart MySQL.
1
sudo systemctl start mysqld