Centos7安裝配置mariadb10.4.13(二進制)

一、下載

[root@localhost src]#wget http://mirrors.dotsrc.org/mariadb//mariadb-10.4.13/bintar-linux-x86_64/mariadb-10.4.13-linux-x86_64.tar.gz
[root@localhost src]# tar -zxvf mariadb-10.4.13-linux-x86_64.tar.gz 
[root@localhost src]# mv mariadb-10.4.13-linux-x86_64 /usr/local/mariadb
[root@localhost mariadb]# ls
bin      CREDITS  docs               include         lib  mysql-test  README-wsrep  share      support-files
COPYING  data     EXCEPTIONS-CLIENT  INSTALL-BINARY  man  README.md   scripts       sql-bench  THIRDPARTY

二、配置

新建組及用戶

[root@localhost mariadb]# groupadd mysql
[root@localhost mariadb]# useradd -s /sbin/nologin -r -g mysql mysql

配置服務

[root@localhost mariadb]# cp support-files/mysql.server /etc/init.d/mysqld
[root@localhost mariadb]# chmod +x /etc/init.d/mysqld 

新建數據目錄與權限

[root@localhost mariadb]# mkdir -p /data/mariadb/
[root@localhost mariadb]# chown -R mysql. /data/mariadb
[root@localhost mariadb]# chown -R mysql:mysql /usr/local/mariadb/

配置my.cnf

[root@localhost mariadb]# vim my.cnf
[mysqld]
basedir=/usr/local/mariadb/
datadir=/data/mariadb/
port=3306
pid-file=/data/mariadb/mysql.pid
socket=/tmp/mysql.sock

[mysqld_safe]
log-error=/data/mariadb/mysql.log

[client]
port=3306
socket=/tmp/mysql.sock
default-character-set=utf8

三、數據庫初始化

/usr/local/mariadb/scripts/mysql_install_db --defaults-file=/usr/local/mariadb/my.cnf --user=mysql --datadir=/data/mariadb/ --basedir=/usr/local/mariadb/

[root@localhost ~]# /usr/local/mariadb/scripts/mysql_install_db --defaults-file=/usr/local/mariadb/my.cnf --user=mysql --datadir=/data/mariadb/ --basedir=/usr/local/mariadb/
Installing MariaDB/MySQL system tables in '/data/mariadb/' ...
OK

To start mysqld at boot time you have to copy
support-files/mysql.server to the right place for your system


Two all-privilege accounts were created.
One is root@localhost, it has no password, but you need to
be system 'root' user to connect. Use, for example, sudo mysql
The second is mysql@localhost, it has no password either, but
you need to be the system 'mysql' user to connect.
After connecting you can set the password, if you would need to be
able to connect as any of these users with a password and without sudo

See the MariaDB Knowledgebase at http://mariadb.com/kb or the
MySQL manual for more instructions.

You can start the MariaDB daemon with:
cd '/usr/local/mariadb/' ; /usr/local/mariadb//bin/mysqld_safe --datadir='/data/mariadb/'

You can test the MariaDB daemon with mysql-test-run.pl
cd '/usr/local/mariadb//mysql-test' ; perl mysql-test-run.pl

Please report any problems at http://mariadb.org/jira

The latest information about MariaDB is available at http://mariadb.org/.
You can find additional information about the MySQL part at:
http://dev.mysql.com
Consider joining MariaDB's strong and vibrant community:
https://mariadb.org/get-involved/

[root@localhost ~]# echo $?
0

四、base目錄權限切回root

[root@localhost mariadb]# chown -R root:root /usr/local/mariadb/

五、配置環境變量

配置環境變量
[root@localhost ~]#echo "PATH=/usr/local/mariadb/bin:$PATH" >/etc/profile.d/mariadb.sh
[root@localhost ~]#chmod +x /etc/profile.d/mariadb.sh 
[root@localhost ~]#source /etc/profile.d/mariadb.sh 

六、啓動與登錄


[root@localhost ~]# /etc/init.d/mysqld start
Starting mysqld (via systemctl):       
[root@localhost ~]# mysql
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2)
報錯,
[root@localhost ~]# ps -ef|grep mysql
root      4386  3375  0 13:54 pts/0    00:00:00 grep --color=auto mysql

解決方法:
1、rm -rf /data/mariadb/* 數據目錄

[root@localhost ~]# rm -rf /data/mariadb/*

2、重新初始化 ,這裏加上–defaults-file=/usr/local/mariadb/my.cnf

[root@localhost ~]# /usr/local/mariadb/scripts/mysql_install_db --defaults-file=/usr/local/mariadb/my.cnf --user=mysql --datadir=/data/mariadb/ --basedir=/usr/local/mariadb/    內容省略

3、換安全模式啓動,登錄改root密碼
mysqld_safe --defaults-file=/usr/local/mariadb/my.cnf &

[root@localhost ~]# mysqld_safe --defaults-file=/usr/local/mariadb/my.cnf &
[1] 4692
[root@localhost ~]# 200605 14:00:41 mysqld_safe Logging to '/data/mariadb/mysql.log'.
200605 14:00:41 mysqld_safe Starting mysqld daemon with databases from /data/mariadb/
[root@localhost ~]# mysql
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 8
Server version: 10.4.13-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)]> 
MariaDB [(none)]> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| performance_schema |
| test               |
+--------------------+
4 rows in set (0.002 sec)
MariaDB [(none)]> use mysql
MariaDB [mysql]> alter user 'root'@'localhost' identified by '123456';
Query OK, 0 rows affected (0.002 sec)
MariaDB [mysql]> FLUSH PRIVILEGES; 
Query OK, 0 rows affected (0.001 sec)

4、配置安全模式

[root@localhost ~]# mysql_secure_installation --basedir=/usr/local/mariadb/
print: /usr/local/mariadb//bin/my_print_defaults

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
haven't set the root password yet, you should just press enter here.

Enter current password for root (enter for none): 
OK, successfully used password, moving on...

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

You already have your root account protected, so you can safely answer 'n'.

Switch to unix_socket authentication [Y/n] y
Enabled successfully!
Reloading privilege tables..
 ... Success!


You already have your root account protected, so you can safely answer 'n'.

Change the 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] 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
 ... 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
 - 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!

5、重啓服務,再mysql登錄

[root@localhost ~]# /etc/init.d/mysqld stop
[root@localhost ~]# /etc/init.d/mysqld start
Starting mysqld (via systemctl):                           [  OK  ]
[root@localhost ~]# ps -ef|grep mysql
root      7104     1  0 14:27 ?        00:00:00 /bin/sh /usr/local/mariadb//bin/mysqld_safe --datadir=/data/mariadb/ --pid-file=/data/mariadb/mysql.pid
mysql     7219  7104  4 14:27 ?        00:00:00 /usr/local/mariadb/bin/mysqld --basedir=/usr/local/mariadb/ --datadir=/data/mariadb/ --plugin-dir=/usr/local/mariadb//lib/plugin --user=mysql --log-error=/data/mariadb/mysql.log --pid-file=/data/mariadb/mysql.pid --socket=/tmp/mysql.sock --port=3306
root      7257  3375  0 14:27 pts/0    00:00:00 grep --color=auto mysql
[root@localhost ~]# 
[root@localhost ~]# mysql  這裏可以正常登錄了
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 9
Server version: 10.4.13-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)]> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| performance_schema |
+--------------------+
3 rows in set (0.001 sec)

------------------end

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章