1 查看是否已经安装过mariadb
[root@www.cndba.cn software]# rpm -qa|grep mariadb
mariadb-libs-5.5.52-1.el7.x86_64
卸载已安装的mariadb数据库
[root@www.cndba.cn software]# rpm -e mariadb-libs-5.5.52-1.el7.x86_64 --nodeps -f
2 创建mysql系统用户组和用户
--创建mysql系统用户组
[root@www.cndba.cn software]# groupadd -r mysql
--创建系统用户mysql并加入到mysql系统用户组
[root@www.cndba.cn software]# useradd -r -g mysql -s /sbin/nologin -d /usr/local/mysql -M mysql
以下是上面创建系统用户mysql的各个参数说明:
-r: 添加系统用户( 这里指将要被创建的系统用户mysql )
-g: 指定要创建的用户所属组( 这里指添加到新系统用户mysql到mysql系统用户组 )
-s: 新系统帐户的登录shell( /sbin/nologin 这里设置为将要被创建系统用户mysql不能用来登录系统 )
-d: 新帐户的主目录( 这里指定将要被创建的系统用户mysql的家目录为 /usr/local/mysql )
-M: 不要创建用户的主目录( 也就是说将要被创建的系统用户mysql不会在 /home 目录下创建 mysql 家目录 )
3 创建目录及赋权
创建数据库存放目录
[root@www.cndba.cn software]# mkdir -p /data/mysql
改变数据库存放目录所属用户及组为 mysql:mysql
[root@www.cndba.cn software]# chown -R mysql:mysql /data/mysql
4 解压二进制程序
[root@www.cndba.cn software]# tar xvf mariadb-10.2.10-linux-x86_64.tar.gz -C /usr/local
mariadb的数据库的目录已经生成,但是这个目录不符合要求,要求mariadb数据库必须放在mysql目录下,所以有两种方法解决,一是改名,将生成的mariadb数据库目录改为mysql,二是创建软链接,我们就选择创建软链接的方式
[root@mariadb3 local]# cd /usr/local
[root@www.cndba.cn local]# ln -s mariadb-10.2.10-linux-x86_64/ mysql
[root@www.cndba.cn local]# ll
total 0
drwxr-xr-x. 2 root root 6 Mar 10 2016 bin
drwxr-xr-x. 2 root root 6 Mar 10 2016 etc
drwxr-xr-x. 2 root root 6 Mar 10 2016 games
drwxr-xr-x. 2 root root 6 Mar 10 2016 include
drwxr-xr-x. 2 root root 6 Mar 10 2016 lib
drwxr-xr-x. 2 root root 6 Mar 10 2016 lib64
drwxr-xr-x. 2 root root 6 Mar 10 2016 libexec
drwxrwxr-x. 2 1021 1004 6 Nov 23 22:58 mariadb-10.2.10-linux-x86_64
lrwxrwxrwx. 1 root root 29 Nov 23 22:59 mysql -> mariadb-10.2.10-linux-x86_64/
drwxr-xr-x. 2 root root 6 Mar 10 2016 sbin
drwxr-xr-x. 5 root root 49 Nov 22 22:02 share
drwxr-xr-x. 2 root root 6 Mar 10 2016 src
5 复制MariaDB配置文件到/etc目录,并修改
[root@www.cndba.cn support-files]# cp my-huge.cnf /etc/my.cnf
[root@www.cndba.cn support-files]# vim /etc/my.cnf
[root@www.cndba.cn support-files]# cat /etc/my.cnf
[client]
password = your_password
default-character-set=utf8
port = 3306
socket = /tmp/mysql.sock
[mysqld]
port = 3306
socket = /tmp/mysql.sock
default-storage-engine=INNODB
character_set_server=utf8
basedir=/usr/local/mysql
datadir=/data/mysql
[mysql]
no-auto-rehash
default-character-set=utf8
6 创建数据库文件
[root@www.cndba.cn support-files]# cd /usr/local/mysql/
[root@www.cndba.cn mysql]# scripts/mysql_install_db --user=mysql --datadir=/data/mysql
注意:创建mysql的系统数据库,系统提供了一个脚本,我们直接可以利用它来生成mysql的系统数据库,这个脚本就在scripts下,但是不要进去运行脚本,否则会报错,必须在/usr/local/mysql/下运行脚本
查看一下生成的数据库文件
[root@www.cndba.cn mysql]# ls /data/mysql/
aria_log.00000001 ib_buffer_pool ib_logfile0 mysql mysql-bin.000002 mysql-bin.state test
aria_log_control ibdata1 ib_logfile1 mysql-bin.000001 mysql-bin.index performance_schema
7 准备日志文件
[root@www.cndba.cn mysql]# mkdir /var/log/mariadb
[root@www.cndba.cn mysql]# chown mysql:mysql /var/log/mariadb/
8 启动服务
复制/usr/local/mysql/support-files目录下mysql.server 到/etc/init.d/mysql 目录下【目的想实现开机自动执行效果】
[root@www.cndba.cn support-files]# cd /usr/local/mysql/support-files
[root@www.cndba.cn support-files]# cp mysql.server /etc/init.d/mysql
--开机自启动
[root@www.cndba.cn support-files]# chkconfig --add mysql
[root@www.cndba.cn support-files]# service mysql start
Starting mysql (via systemctl): [ OK ]
9 配置环境变量
[root@www.cndba.cn /]# vi /etc/profile
添加:
export PATH=$PATH:/usr/local/mysql/bin/
[root@www.cndba.cn /]# source /etc/profile
10 初始化MariaDB
[root@www.cndba.cn /]# cd /usr/local/mysql
[root@www.cndba.cn mysql]# ./mysql_secure_installation
-bash: ./mysql_secure_installation: No such file or directory
[root@www.cndba.cn mysql]# mysql_secure_installation
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] root
Set root password? [Y/n] root
Set root password? [Y/n] y
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]
... 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]
... 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]
- 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]
... 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!
11 数据库安装成功
[root@www.cndba.cn mysql]# mysql -uroot -proot
Welcome to the MariaDB monitor. Commands end with ; or /g.
Your MariaDB connection id is 18
Server version: 10.2.10-MariaDB-log MariaDB Server
Copyright (c) 2000, 2017, Oracle, MariaDB Corporation Ab and others.
Type 'help;' or '/h' for help. Type '/c' to clear the current input statement.
MariaDB [(none)]>
MariaDB [(none)]> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
+--------------------+
3 rows in set (0.00 sec)
版权声明:本文为博主原创文章,未经博主允许不得转载。