centos7 Mariadb 安裝 與 二進制編譯安裝

我們用yum源安裝Mariadb

1、安裝MariaDB
[root@node1 ~]# yum -y install mariadb mariadb-server
安裝完成MariaDB,首先啓動MariaDB
[root@node1 ~]# systemctl start mariadb
設置開機啓動
[root@node1 ~]# systemctl enable mariadb
Created symlink from /etc/systemd/system/multi-user.target.wants/mariadb.service to /usr/lib/systemd/system/mariadb.service.
接下來進行MariaDB的相關簡單配置
[root@node1 ~]# 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] y 是否設置root用戶密碼,輸入y並回車或直接回車
New password: 設置root用戶的密碼
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] 是否禁止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] 是否刪除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] 是否重新加載權限表,回車
... 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! (初始化MariaDB完成,接下來測試登錄)!
下面我們正式進入 mariadb 的使用中!!
[root@node1 ~]# mysql -u root -p (-u:用戶名,默認爲root,-p:用戶密碼)
Enter password: (此處輸入設置的密碼)
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection id is 11
Server version: 5.5.60-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)]>
2、配置MariaDB的字符集

文件/etc/my.cnf

[root@node1 ~]# vim /etc/my.cnf
[mysqld]
init_connect='SET collation_connection = utf8_unicode_ci'
init_connect='SET NAMES utf8'
character-set-server=utf8
collation-server=utf8_unicode_ci
skip-character-set-client-handshake
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock

Disabling symbolic-links is recommended to prevent assorted security risks

symbolic-links=0

Settings user and group are ignored when systemd is used.

If you need to run mysqld under a different user or group,

customize your systemd unit file for mariadb according to the

instructions in http://fedoraproject.org/wiki/Systemd

[mysqld_safe]
log-error=/var/log/mariadb/mariadb.log
pid-file=/var/run/mariadb/mariadb.pid

#

include all files from the config directory

#
!includedir /etc/my.cnf.d
在[mysqld]標籤下添加
“ init_connect='SET collation_connection = utf8_unicode_ci'
init_connect='SET NAMES utf8'
character-set-server=utf8
collation-server=utf8_unicode_ci
skip-character-set-client-handshake ”

文件/etc/my.cnf.d/client.cnf

[root@node1 ~]# vim /etc/my.cnf.d/client.cnf

These two groups are read by the client library

Use it for options that affect all clients, but not the server

[client]

default-character-set=utf8

This group is not read by mysql client library,

If you use the same .cnf file for MySQL and MariaDB,

use it for MariaDB-only client options

[client-mariadb]
在[client]中添加: default-character-set=utf8

文件/etc/my.cnf.d/mysql-clients.cnf

[root@node1 ~]# vim /etc/my.cnf.d/mysql-clients.cnf

These groups are read by MariaDB command-line tools

Use it for options that affect only one utility

[mysql]

default-character-set=utf8
[mysql_upgrade]

[mysqladmin]

[mysqlbinlog]

[mysqlcheck]

[mysqldump]

[mysqlimport]

[mysqlshow]

[mysqlslap]
在[mysql]中添加: default-character-set=utf8

全部配置完成,重啓mariadb systemctl restart mariadb

3、之後進入MariaDB查看字符集
[root@node1 ~]# mysql -u root -p
Enter password:
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection id is 2
Server version: 5.5.60-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 variables like "%character%";show variables like "%collation%";
+--------------------------+----------------------------+
| Variable_name | Value |
+--------------------------+----------------------------+
| character_set_client | utf8 |
| character_set_connection | utf8 |
| character_set_database | utf8 |
| character_set_filesystem | binary |
| character_set_results | utf8 |
| character_set_server | utf8 |
| character_set_system | utf8 |
| character_sets_dir | /usr/share/mysql/charsets/ |
+--------------------------+----------------------------+
8 rows in set (0.00 sec)

+----------------------+-----------------+
| Variable_name | Value |
+----------------------+-----------------+
| collation_connection | utf8_unicode_ci |
| collation_database | utf8_unicode_ci |
| collation_server | utf8_unicode_ci |
+----------------------+-----------------+
3 rows in set (0.00 sec)
MariaDB [(none)]>
至此,我們的實驗已經完成!

我們現在做mariadb 的二進制安裝:

注:所謂二進制包就是官方編譯好了的,我們稍加配置即可使用,我們要解壓縮到官方編譯的路徑上“ /usr/local/ ”目錄下,因爲安裝好yum源後會有“ mysql ”賬號生成,同時,也會創建一個組也是“ mysql ”;所以,在解壓縮前,我們先手動創建mysql賬號,
1、首先將官方安裝包rz到虛擬機:
[root@centos7 ~]# rz
[root@centos7 ~]# ls /usr/local/
bin etc games include lib lib64 libexec sbin share src
[root@centos7 ~]# useradd -s /sbin/nologin -r mysql
[root@centos7 ~]# getent passwd mysql
mysql:x:988:982::/home/mysql:/sbin/nologin
[root@centos7 ~]# id mysql
uid=988(mysql) gid=982(mysql) groups=982(mysql)
[root@centos7 ~]# tar xvf mariadb-10.2.22-linux-x86_64.tar.gz -C /usr/local/
[root@centos7 ~]# cd /usr/local/
[root@centos7 /usr/local]# ls
bin games lib libexec sbin src
etc include lib64 mariadb-10.2.22-linux-x86_64 share
[root@centos7 /usr/local]# ln -s mariadb-10.2.22-linux-x86_64/ mysql
[root@centos7 /usr/local]# ll
total 0
drwxr-xr-x. 2 root root 6 Apr 11 2018 bin
drwxr-xr-x. 2 root root 6 Apr 11 2018 etc
drwxr-xr-x. 2 root root 6 Apr 11 2018 games
drwxr-xr-x. 2 root root 6 Apr 11 2018 include
drwxr-xr-x. 2 root root 6 Apr 11 2018 lib
drwxr-xr-x. 2 root root 6 Apr 11 2018 lib64
drwxr-xr-x. 2 root root 6 Apr 11 2018 libexec
drwxrwxr-x 12 1021 1004 290 Feb 11 2019 mariadb-10.2.22-linux-x86_64
lrwxrwxrwx 1 root root 29 Feb 10 22:09 mysql -> mariadb-10.2.22-linux-x86_64/
drwxr-xr-x. 2 root root 6 Apr 11 2018 sbin
drwxr-xr-x. 5 root root 49 Jan 3 22:01 share
drwxr-xr-x. 2 root root 6 Apr 11 2018 src
上述內容解釋:用軟連接把文件改名爲mysql,
2、[root@centos7 /usr/local]# pwd
/usr/local
[root@centos7 /usr/local]# ll /usr/local/mysql/
total 176
drwxrwxr-x 2 1021 1004 4096 Dec 20 21:15 bin
-rw-r--r-- 1 1021 1004 17987 Feb 10 07:24 COPYING
-rw-r--r-- 1 1021 1004 86263 Feb 10 07:24 COPYING.thirdparty
-rw-r--r-- 1 1021 1004 2354 Feb 10 07:24 CREDITS
drwxrwxr-x 3 1021 1004 18 Feb 11 2019 data
-rw-r--r-- 1 1021 1004 8245 Feb 10 07:24 EXCEPTIONS-CLIENT
drwxrwxr-x 3 1021 1004 19 Feb 11 2019 include
-rw-r--r-- 1 1021 1004 8694 Feb 10 07:24 INSTALL-BINARY
drwxrwxr-x 5 1021 1004 335 Dec 20 21:15 lib
drwxrwxr-x 4 1021 1004 30 Feb 11 2019 man
drwxrwxr-x 11 1021 1004 4096 Feb 11 2019 mysql-test
-rw-r--r-- 1 1021 1004 2469 Feb 10 07:24 README.md
-rw-r--r-- 1 1021 1004 19561 Feb 10 07:24 README-wsrep
drwxrwxr-x 2 1021 1004 30 Feb 11 2019 scripts
drwxrwxr-x 32 1021 1004 4096 Feb 11 2019 share
drwxrwxr-x 4 1021 1004 4096 Feb 11 2019 sql-bench
drwxrwxr-x 3 1021 1004 275 Feb 11 2019 support-files
此時,我們用ll看到,文件都是不存在文件名和組名,所以要改,
[root@centos7 /usr/local]# chown -R root.root /usr/local/mysql/
[root@centos7 /usr/local]# ll /usr/local/mysql/
total 176
drwxrwxr-x 2 root root 4096 Dec 20 21:15 bin
-rw-r--r-- 1 root root 17987 Feb 10 07:24 COPYING
-rw-r--r-- 1 root root 86263 Feb 10 07:24 COPYING.thirdparty
-rw-r--r-- 1 root root 2354 Feb 10 07:24 CREDITS
drwxrwxr-x 3 root root 18 Feb 11 2019 data
-rw-r--r-- 1 root root 8245 Feb 10 07:24 EXCEPTIONS-CLIENT
drwxrwxr-x 3 root root 19 Feb 11 2019 include
-rw-r--r-- 1 root root 8694 Feb 10 07:24 INSTALL-BINARY
drwxrwxr-x 5 root root 335 Dec 20 21:15 lib
drwxrwxr-x 4 root root 30 Feb 11 2019 man
drwxrwxr-x 11 root root 4096 Feb 11 2019 mysql-test
-rw-r--r-- 1 root root 2469 Feb 10 07:24 README.md
-rw-r--r-- 1 root root 19561 Feb 10 07:24 README-wsrep
drwxrwxr-x 2 root root 30 Feb 11 2019 scripts
drwxrwxr-x 32 root root 4096 Feb 11 2019 share
drwxrwxr-x 4 root root 4096 Feb 11 2019 sql-bench
drwxrwxr-x 3 root root 275 Feb 11 2019 support-files
以上內容就可以看到,文件屬於root文件名root組名。
root@centos7 /usr/local]# ll /usr/local/mysql/bin/
total 812908
-rwxr-xr-x 1 root root 12231048 Feb 10 07:30 mysql
-rwxr-xr-x 1 root root 117334166 Feb 10 07:48 mysqld
此文件夾下放了二進制程序,mysql是客戶端工具,mysqld是服務器端程序,爲了使用該文件夾的程序較爲方便,我們要修改$PATH:
[root@centos7 /usr/local]# vim /etc/profile.d/env.sh
PATH=/usr/local/mysql/bin:$PATH
[root@centos7 /usr/local]# . /etc/profile.d/env.sh (使其生效)
[root@centos7 /usr/local]# echo $PATH
/usr/local/mysql/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin
[root@centos7 /usr/local]# ls
bin games lib libexec mysql share
etc include lib64 mariadb-10.2.22-linux-x86_64 sbin src
[root@centos7 /usr/local]# ls mysql/
bin EXCEPTIONS-CLIENT mysql-test sql-bench
COPYING include README.md support-files
COPYING.thirdparty INSTALL-BINARY README-wsrep
CREDITS lib scripts
data man share
此時,變量問題,我們已經解決。
3、創建存放數據庫的文件:
[root@centos7 /usr/local]# mkdir /data/mysql -pv
mkdir: created directory ‘/data/mysql’
[root@centos7 /usr/local]# ll -d /data/mysql/
drwxr-xr-x 2 root root 6 Feb 10 22:29 /data/mysql/
[root@centos7 /usr/local]# chown mysql.mysql /data/mysql/
[root@centos7 /usr/local]# ls /data/mysql/
[root@centos7 /usr/local]#
我們創建的文件夾有問題,要更改所屬組,但是由上可以看到,文件夾裏無內容。
[root@centos7 /usr/local]# cd mysql/
[root@centos7 /usr/local/mysql]# ls
bin EXCEPTIONS-CLIENT mysql-test sql-bench
COPYING include README.md support-files
COPYING.thirdparty INSTALL-BINARY README-wsrep
CREDITS lib scripts
data man share
[root@centos7 /usr/local/mysql]# cd scripts/
[root@centos7 /usr/local/mysql/scripts]# ls
mysql_install_db
其中該腳本mysql_install_db就是用來生成系統數據庫的,
[root@centos7 /usr/local/mysql/scripts]# pwd
/usr/local/mysql/scripts
[root@centos7 /usr/local/mysql/scripts]# cd .
[root@centos7 /usr/local/mysql/scripts]# cd ..
[root@centos7 /usr/local/mysql]# ./scripts/mysql_install_db --datadir=/data/mysql --user=mysql
Installing MariaDB/MySQL system tables in '/data/mysql' ...
OK

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

PLEASE REMEMBER TO SET A PASSWORD FOR THE MariaDB root USER !
To do so, start the server, then issue the following commands:

'./bin/mysqladmin' -u root password 'new-password'
'./bin/mysqladmin' -u root -h centos7 password 'new-password'

Alternatively you can run:
'./bin/mysql_secure_installation'

which will also give you the option of removing the test
databases and anonymous user created by default. This is
strongly recommended for production servers.

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

You can start the MariaDB daemon with:
cd '.' ; ./bin/mysqld_safe --datadir='/data/mysql'

You can test the MariaDB daemon with mysql-test-run.pl
cd './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/
此時已經安裝完成,我們必須在/usr/local/mysql/script下才能運行腳本,否則,在子目錄下不能運行。

4、[root@centos7 /usr/local/mysql]# ls /data/mysql/ -l
total 110620
-rw-rw---- 1 mysql mysql 16384 Feb 10 22:38 aria_log.00000001
-rw-rw---- 1 mysql mysql 52 Feb 10 22:38 aria_log_control
-rw-rw---- 1 mysql mysql 938 Feb 10 22:38 ib_buffer_pool
-rw-rw---- 1 mysql mysql 12582912 Feb 10 22:38 ibdata1
-rw-rw---- 1 mysql mysql 50331648 Feb 10 22:38 ib_logfile0
-rw-rw---- 1 mysql mysql 50331648 Feb 10 22:38 ib_logfile1
drwx------ 2 mysql root 4096 Feb 10 22:38 mysql
drwx------ 2 mysql mysql 20 Feb 10 22:38 performance_schema
drwx------ 2 mysql root 6 Feb 10 22:38 test
此時已經生成相應的數據庫了,如上。
[root@centos7 /usr/local/mysql]# ls
bin include README-wsrep
COPYING INSTALL-BINARY scripts
COPYING.thirdparty lib share
CREDITS man sql-bench
data mysql-test support-files
EXCEPTIONS-CLIENT README.md
[root@centos7 /usr/local/mysql]# cd support-files/
[root@centos7 /usr/local/mysql/support-files]# ls
binary-configure my-medium.cnf policy
magic my-small.cnf wsrep.cnf
my-huge.cnf mysqld_multi.server wsrep_notify
my-innodb-heavy-4G.cnf mysql-log-rotate
my-large.cnf mysql.server
上述文件中就已可以用作mysql配置文件的模板範例配置文件。
5、[root@centos7 /usr/local/mysql/support-files]# mkdir /etc/mysql
[root@centos7 /usr/local/mysql/support-files]# cp my-huge.cnf /etc/mysql/my.cnf
[root@centos7 /usr/local/mysql/support-files]# vim /etc/mysql/my.cnf
[mysqld]
datadir=/data/mysql
port = 3306
socket = /tmp/mysql.sock
skip-external-locking
key_buffer_size = 384M
max_allowed_packet = 1M
table_open_cache = 512
sort_buffer_size = 2M
read_buffer_size = 2M
read_rnd_buffer_size = 8M
myisam_sort_buffer_size = 64M
thread_cache_size = 8
query_cache_size = 32M
我們創建一個文件並cp文件,編輯進入“ ”datadir=/data/mysql ”內容。
我們欠缺一個啓動腳本,我們拷貝一份並改名,【】我們把它啓動起來,如下:
6、[root@centos7 /usr/local/mysql/support-files]# ls
binary-configure my-medium.cnf policy
magic my-small.cnf wsrep.cnf
my-huge.cnf mysqld_multi.server wsrep_notify
my-innodb-heavy-4G.cnf mysql-log-rotate
my-large.cnf mysql.server
[root@centos7 /usr/local/mysql/support-files]# cp mysql.server /etc/init.d/mysqld
[root@centos7 /usr/local/mysql/support-files]# cd /etc/init.d
[root@centos7 /etc/init.d]# ls
functions mysqld netconsole network README
[root@centos7 /etc/init.d]# service mysqld status
ERROR! MariaDB is not running
現在,我們啓動服務,並查看端口:
[root@centos7 /etc/init.d]# service mysqld start
Reloading systemd: [ OK ]
Starting mysqld (via systemctl): [ OK ]
[root@centos7 /etc/init.d]# ss -ntl
State Recv-Q Send-Q Local Address:Port Peer Address:Port
LISTEN 0 128 :111 :
LISTEN 0 128
:6000 :
LISTEN 0 5 192.168.122.1:53 :
LISTEN 0 128 :22 :
LISTEN 0 128 127.0.0.1:631
:
LISTEN 0 100 127.0.0.1:25
:
LISTEN 0 128 127.0.0.1:6010
:
LISTEN 0 128 127.0.0.1:6011
:
LISTEN 0 80 :::3306 :::

LISTEN 0 128 :::111 :::
LISTEN 0 128 :::80 :::

LISTEN 0 128 :::6000 :::
LISTEN 0 128 :::22 :::

LISTEN 0 128 ::1:631 :::
LISTEN 0 100 ::1:25 :::

LISTEN 0 128 ::1:6010 :::
LISTEN 0 128 ::1:6011 :::

[root@centos7 /etc/init.d]# ls /data/mysql/
aria_log.00000001 ibdata1 multi-master.info performance_schema
aria_log_control ib_logfile0 mysql test
centos7.pid ib_logfile1 mysql-bin.000001
ib_buffer_pool ibtmp1 mysql-bin.index
[root@centos7 /etc/init.d]# ll /data/mysql/
total 122920
-rw-rw---- 1 mysql mysql 16384 Feb 10 22:38 aria_log.00000001
-rw-rw---- 1 mysql mysql 52 Feb 10 22:38 aria_log_control
-rw-rw---- 1 mysql mysql 6 Feb 10 22:55 centos7.pid
-rw-rw---- 1 mysql mysql 938 Feb 10 22:38 ib_buffer_pool
-rw-rw---- 1 mysql mysql 12582912 Feb 10 22:55 ibdata1
-rw-rw---- 1 mysql mysql 50331648 Feb 10 22:55 ib_logfile0
-rw-rw---- 1 mysql mysql 50331648 Feb 10 22:38 ib_logfile1
-rw-rw---- 1 mysql mysql 12582912 Feb 10 22:55 ibtmp1
-rw-rw---- 1 mysql mysql 0 Feb 10 22:55 multi-master.info
drwx------ 2 mysql root 4096 Feb 10 22:38 mysql
-rw-rw---- 1 mysql mysql 328 Feb 10 22:55 mysql-bin.000001
-rw-rw---- 1 mysql mysql 19 Feb 10 22:55 mysql-bin.index
drwx------ 2 mysql mysql 20 Feb 10 22:38 performance_schema
drwx------ 2 mysql root 6 Feb 10 22:38 test
文件已經生成,我們的MySQL服務就可以連接了,10.2.22版本,如下:
[root@centos7 /etc/init.d]# mysql
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection id is 10
Server version: 10.2.22-MariaDB-log 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)]>
我們爲了安全,要跑一個安全加固腳本,
7、root@centos7 /etc/init.d]# which mysql_secure_installation
/usr/local/mysql/bin/mysql_secure_installation
[root@centos7 /etc/init.d]# 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] 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] y 禁止遠程登錄
... 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 刪除text賬號

  • 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@centos7 /etc/init.d]# mysql
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)
可以看到匿名用戶就登陸不了了,
[root@centos7 /etc/init.d]# mysql -uroot -p12345gxy
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection id is 20
Server version: 10.2.22-MariaDB-log 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)]>
只有輸入正確的密碼用戶才能登陸,到此,二進制編譯安裝已經完成。
步驟總結:
1 準備用戶和組
useradd -s /sbin/nologin -r mysql
2 準備二進制程序文件
tar xvf mariadb-10.2.22-linux-x86_64.tar.gz -C /usr/local/
cd /usr/local/
ln -s mariadb-10.2.22-linux-x86_64/ mysql
chown -R root.root /usr/local/mysql/
3 PATH變量
cat /etc/profile.d/env.sh
PATH=/usr/local/mysql/bin:$PATH
4 準備數據庫數據目錄和數據 (4和2是兩碼事,不要混淆)
mkdir /data/mysql -pv
chown mysql.mysql /data/mysql/
cd /usr/local/mysql
./scripts/mysql_install_db --datadir=/data/mysql --user=mysql
5 準備Mysql的服務器端的配置文件
mkdir /etc/mysql
cp /usr/local/mysql/support-files/my-huge.cnf /etc/mysql/my.cnf

vim /etc/mysql/my.cnf
[mysqld]
datadir=/data/mysql 加一行
6 準備服務啓動腳本
cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld
chkconfig --add mysqld
service mysqld start
7 安全加固
mysql_secure_installation

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