前段时间买了台 云服务想着不用在本地开虚拟机,这样对自己的笔记本来说是个解脱。然后就准备在上面装个MariaDB,虽然网上教程一大堆,但是知识只有掌握在自己手里才算是真的掌握了。为了加深印象,所以我准备从新装一次,以下是操作过程,记录一下。
1.首先查看是否安装了MariaDB
-
[root@VM-0-16-centos ~]
# rpm -qa|grep mariadb
-
mariadb-5.5.68-1.el7.x86_64
-
mariadb-server-5.5.68-1.el7.x86_64
-
mariadb-libs-5.5.68-1.el7.x86_64
-
[root@VM-0-16-centos ~]
#
2.卸载MariaDB
-
[root@VM-0-16-centos ~]
# yum remove mariadb
-
······
-
Removed:
-
mariadb.x86_64 1:5.5.68-1.el7
-
-
Dependency Removed:
-
mariadb-server.x86_64 1:5.5.68-1.el7
-
-
Complete!
-
[root@VM-0-16-centos ~]
#
3.删除遗留目录
-
[root@VM-0-16-centos ~]
# ll /etc/my.cnf
-
-rw-r--r-- 1 root root 753 Dec 21 15:12 /etc/my.cnf
-
[root@VM-0-16-centos ~]
# ll /var/lib/mysql/
-
total 28700
-
-rw-rw---- 1 mysql mysql 16384 Dec 22 10:42 aria_log.00000001
-
-rw-rw---- 1 mysql mysql 52 Dec 22 10:42 aria_log_control
-
-rw-rw---- 1 mysql mysql 18874368 Dec 22 10:42 ibdata1
-
-rw-rw---- 1 mysql mysql 5242880 Dec 22 10:42 ib_logfile0
-
-rw-rw---- 1 mysql mysql 5242880 Dec 21 14:59 ib_logfile1
-
drwx------ 2 mysql mysql 4096 Dec 21 14:59 mysql
-
drwx------ 2 mysql mysql 4096 Dec 21 14:59 performance_schema
-
[root@VM-0-16-centos ~]
# rm -rf /etc/my.cnf /var/lib/mysql
-
[root@VM-0-16-centos ~]
#
4.重新安装
-
[root
@VM-
0-
16-centos ~]
# yum -y install mariadb mariadb-server #安装mariadb
-
[root
@VM-
0-
16-centos ~]
# systemctl start mariadb #启动mariadb
-
[root
@VM-
0-
16-centos ~]
# systemctl enable mariadb #开机启动mariadb
5.配置mariadb
-
[root@VM-0-16-centos ~]
# mysql_secure_installation #配置mariadb
-
-
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用户密码,输入y并回车
-
New password: #输入root用户密码
-
Re-enter new password: #再输入一次root用户密码
-
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] n #是否禁止root远程登录,根据自己的需求选择y/n并回车
-
... skipping.
-
-
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!
-
[root@VM-0-16-centos ~]
#
6.新增新用户及数据库
-
[root@VM-0-16-centos ~]
# mysql -uroot -p
-
Enter password:
-
Welcome to the MariaDB monitor. Commands end with ; or \g.
-
Your MariaDB connection
id is 13
-
Server version: 5.5.68-MariaDB MariaDB Server
-
-
Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.
-
-
Type
'help;' or
'\h'
for
help. Type
'\c' to clear the current input statement.
-
-
MariaDB [(none)]> create user eric@
'%' identified by
'eric';
#新建用户,%代表任意ip都可以登录
-
Query OK, 0 rows affected (0.00 sec)
-
-
MariaDB [(none)]> create database ericdb;
#创建数据库
-
MariaDB [(none)]> grant all privileges on ericdb.* to eric@
'%' ;
#为eric用户授予ericdb的所有权限
-
Query OK, 0 rows affected (0.00 sec)
-
-
接下来就可以使用eric用户在ericdb里做操作啦,以上。