下载二进制软件包
#wget https://mirrors.tuna.tsinghua.edu.cn/mariadb//mariadb-10.2.23/bintar-linux-x86_64/mariadb-10.2.23-linux-x86_64.tar.gz -P /data
--2019-07-06 16:31:12-- https://mirrors.tuna.tsinghua.edu.cn/mariadb//mariadb-10.2.23/bintar-linux-x86_64/mariadb-10.2.23-linux-x86_64.tar.gz
Resolving mirrors.tuna.tsinghua.edu.cn (mirrors.tuna.tsinghua.edu.cn)... 101.6.8.193, 2402:f000:1:408:8100::1
Connecting to mirrors.tuna.tsinghua.edu.cn (mirrors.tuna.tsinghua.edu.cn)|101.6.8.193|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 456950538 (436M) [application/x-gzip]
Saving to: ‘/data/mariadb-10.2.23-linux-x86_64.tar.gz’
100%[========================================>] 456,950,538 4.11MB/s in 2m 17s
2019-07-06 16:33:29 (3.17 MB/s) - ‘/data/mariadb-10.2.23-linux-x86_64.tar.gz’ saved [456950538/456950538]
创建mysql系统用户
#useradd -r -s /sbin/nologin -d /data/mysql mysql
#mkdir /data/mysql
#chown -R mysql.mysql /data/mysql/ #修改权限
解压缩
#tar xvf mariadb-10.2.23-linux-x86_64.tar.gz -C /usr/local/
#cd /usr/local/
查看是否解压缩成功
#ll mariadb-10.2.23-linux-x86_64/
total 176
drwxrwxr-x 2 1021 1004 4096 Dec 20 2018 bin
-rw-r--r-- 1 1021 1004 17987 Mar 24 01:30 COPYING
-rw-r--r-- 1 1021 1004 86263 Mar 24 01:30 COPYING.thirdparty
-rw-r--r-- 1 1021 1004 2354 Mar 24 01:30 CREDITS
drwxrwxr-x 3 1021 1004 18 Mar 25 09:24 data
-rw-r--r-- 1 1021 1004 8245 Mar 24 01:30 EXCEPTIONS-CLIENT
drwxrwxr-x 3 1021 1004 19 Mar 25 09:24 include
-rw-r--r-- 1 1021 1004 8694 Mar 24 01:30 INSTALL-BINARY
drwxrwxr-x 5 1021 1004 335 Dec 20 2018 lib
drwxrwxr-x 4 1021 1004 30 Mar 25 09:24 man
drwxrwxr-x 11 1021 1004 4096 Mar 25 09:24 mysql-test
-rw-r--r-- 1 1021 1004 2469 Mar 24 01:30 README.md
-rw-r--r-- 1 1021 1004 19561 Mar 24 01:30 README-wsrep
drwxrwxr-x 2 1021 1004 30 Mar 25 09:24 scripts
drwxrwxr-x 32 1021 1004 4096 Mar 25 09:24 share
drwxrwxr-x 4 1021 1004 4096 Mar 25 09:24 sql-bench
drwxrwxr-x 3 1021 1004 275 Mar 25 09:24 support-files
创建软链接 mysql
#ln -s mariadb-10.2.23-linux-x86_64/ mysql
编辑配置文件my.cnf
#mkdir /etc/mysql
#cp support-files/my-huge.cnf /etc/mysql/my.cnf #拷贝配置文件模板到/etc/mysql/改名为my.cnf
#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
生成数据库文件
#./scripts/mysql_install_db --datadir=/data/mysql --user=mysql
Installing MariaDB/MySQL system tables in '/data/mysql' ...
2019-07-06 16:43:42 140329075038016 [Warning] 'THREAD_CONCURRENCY' is deprecated and will be removed in a future release.
2019-07-06 16:43:43 140329074452224 [Warning] Failed to load slave replication state from table mysql.gtid_slave_pos: 1146: Table 'mysql.gtid_slave_pos' doesn't exist
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_1.localdomain 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/
确认是否生成成功
#ls /data/mysql/
aria_log.00000001 ibdata1 mysql mysql-bin.state
aria_log_control ib_logfile0 mysql-bin.000001 performance_schema
ib_buffer_pool ib_logfile1 mysql-bin.index test
添加为系统服务名字为mysqld
#cp support-files/mysql.server /etc/rc.d/init.d/mysqld
#chkconfig --add mysqld
#chkconfig --list #确认是否添加成功
Note: This output shows SysV services only and does not include native
systemd services. SysV configuration data might be overridden by native
systemd configuration.
If you want to list systemd services use 'systemctl list-unit-files'.
To see services enabled on particular target use
'systemctl list-dependencies [target]'.
mysqld 0:off 1:off 2:on 3:on 4:on 5:on 6:off
netconsole 0:off 1:off 2:off 3:off 4:off 5:off 6:off
network 0:off 1:off 2:on 3:on 4:on 5:on 6:off
#service mysqld start #启动服务
Starting mysqld (via systemctl): [ OK ]
#ss -ntl #查看端口是否监听成功
State Recv-Q Send-Q Local Address:Port Peer Address:Port
LISTEN 0 80 :::3306 :::*
#echo export PATH=/usr/local/mysql/bin/:$PATH > /etc/profile.d/mysql.sh 设置PATH变量
#source /etc/profile.d/mysql.sh
#mysql 测试是否可以连接数据库
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection id is 10
Server version: 10.2.23-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)]> 成功
MariaDB [(none)]> exit #退出