某山寨

z4zr的待调教小窝

CentOS7调教----安装MariaDB(MySQL)

CentOS7调教----安装MariaDB(MySQL)

CentOS7.0中使用MariaDB替代了MySQL数据库,不过它们一个爹,对于初学者把它当成MySQL使用无任何影响

## Step1
下载安装MariaDB
yum install mariadb mariadb-server

## Step2
启动mariadb服务并把此服务设置为开机自启动
systemctl start mariadb.service
systemctl enable mariadb.service


## Step3
拷贝配置文件
cp /usr/share/mysql/my-medium.cnf /etc/my.cnf
在/usr/share/mysql/可以找到几个现成的配置文件,根据具体情况选择

## Step4
为数据库设置密码。。。赤裸裸的命令啊。。。
mysql_secure_installation
```
/usr/bin/mysql_secure_installation:行379: find_mysql_client: 未找到命令

NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MariaDB
SERVERS IN PRODUCTION USE! PLEASE READ EACH STEP CAREFULLY!

In order to log into MariaDB to secure it, we'll need the current
password for the root user. If you've just installed MariaDB, 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):
OK, successfully used password, moving on...

Setting the root password ensures that nobody can log into the MariaDB
root user without the proper authorisation.

Set root password? [Y/n] y #是否设置root密码
New password:
Re-enter new password:
Password updated successfully!
Reloading privilege tables..
... Success!


By default, a MariaDB installation has an anonymous user, allowing anyone
to log into MariaDB 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 #是否删除匿名用户
... 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 #是否删禁止root用户远程登录
... Success!

By default, MariaDB 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
- 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 #是否立即刷新权限
... Success!

Cleaning up...

All done! If you've completed all of the above steps, your MariaDB
installation should now be secure.

Thanks for using MariaDB!
```

## Step5
测试登录
mysql -u root -p

## Step6
别忘了防火墙放行啊。。。
```
firewall-cmd --add-service=mysql
firewall-cmd --add-service=mysql --permanent
firewall-cmd --reload
```

额,打完收工......


Warning: file_get_contents(http://api.hitokoto.us/rand): failed to open stream: Connection timed out in /data/htdocs/z4zr.host.smartgslb.com/usr/themes/Wcat/functions.php on line 87

文章二维码