CentOS7.4安装Mariadb10.3.11操作实录

1、解压从mariadb.org网站上下载的10.3.11版本的mariadb安装压缩包
[root@mysql1 ~]#
[root@mysql1 ~]# cd /mariadb
[root@mysql1 mariadb]# ll
total 0
drwxrwxr-x 13 1021 1004 302 Nov 19 15:54 mariadb-10.3.11-linux-systemd-x86_64.tar.gz
[root@mysql1 mariadb]#tar -zxvf mariadb-10.3.11-linux-systemd-x86_64.tar.gz
[root@mysql1 mariadb]#
[root@mysql1 mariadb]# cd mariadb-10.3.11-linux-systemd-x86_64/
[root@mysql1 mariadb-10.3.11-linux-systemd-x86_64]# ll
total 180
drwxr-xr-x  2 1021 1004  4096 Sep 22 08:14 bin
-rw-r--r--  1 1021 1004 17987 Nov 16 13:04 COPYING
-rw-r--r--  1 1021 1004 86263 Nov 16 13:04 COPYING.thirdparty
-rw-r--r--  1 1021 1004  2354 Nov 16 13:04 CREDITS
drwxrwxr-x  3 1021 1004    18 Nov 19 15:54 data
drwxrwxr-x  2 1021 1004    81 Nov 19 15:54 docs
-rw-r--r--  1 1021 1004  8245 Nov 16 13:04 EXCEPTIONS-CLIENT
drwxrwxr-x  3 1021 1004    19 Nov 19 15:54 include
-rw-r--r--  1 1021 1004  8694 Nov 16 13:04 INSTALL-BINARY
drwxr-xr-x  5 1021 1004  4096 Sep 22 22:14 lib
drwxrwxr-x  4 1021 1004    30 Nov 19 15:54 man
drwxrwxr-x  9 1021 1004  4096 Nov 19 15:54 mysql-test
-rw-r--r--  1 1021 1004  2469 Nov 16 13:04 README.md
-rw-r--r--  1 1021 1004 19510 Nov 16 13:04 README-wsrep
drwxrwxr-x  2 1021 1004    30 Nov 19 15:54 scripts
drwxrwxr-x 32 1021 1004  4096 Nov 19 15:54 share
drwxrwxr-x  4 1021 1004  4096 Nov 19 15:54 sql-bench
drwxrwxr-x  4 1021 1004   180 Nov 19 15:54 support-files

2、查看官方提供的安装文件INSTALL-BINARY
[root@mysql1 mariadb-10.3.11-linux-systemd-x86_64]# more INSTALL-BINARY

MariaDB and MySQL have identical install methods. In this document we
describe how to install MariaDB; However all documentation at www.mysql.com
also applies.


2.2. Installing MariaDB from Generic Binaries on Unix/Linux

   The basic commands that you must execute to install and use a
   MariaDB binary distribution are:

shell> groupadd mysql
shell> useradd -g mysql mysql
shell> cd /usr/local
shell> gunzip < /path/to/mysql-VERSION-OS.tar.gz | tar xvf -
shell> ln -s full-path-to-mysql-VERSION-OS mysql
shell> cd mysql
shell> chown -R mysql .
shell> chgrp -R mysql .
shell> scripts/mysql_install_db --user=mysql
shell> chown -R root .
shell> chown -R mysql data
shell> bin/mysqld_safe --user=mysql &

Note

   This procedure does not set up any passwords for MariaDB accounts.
   After following the procedure, proceed to Section 2.13,
   "Post-Installation Setup and Testing."

3、根据INSTALL-BINARY提到的步骤创建用户,创建从/usr/local/mysql到mysql安装包的链接
[root@mysql1 mariadb-10.3.11-linux-systemd-x86_64]#
[root@mysql1 mariadb-10.3.11-linux-systemd-x86_64]#
[root@mysql1 mariadb-10.3.11-linux-systemd-x86_64]# cd
[root@mysql1 ~]#
[root@mysql1 ~]# groupadd mysql
[root@mysql1 ~]# useradd -g mysql mysql
[root@mysql1 ~]# cd /usr/local
[root@mysql1 local]# ln -s /mariadb/mariadb-10.3.11-linux-systemd-x86_64/ mysql
[root@mysql1 local]# ll
total 0
drwxr-xr-x. 2 root root  6 Nov  5  2016 bin
drwxr-xr-x. 2 root root  6 Nov  5  2016 etc
drwxr-xr-x. 2 root root  6 Nov  5  2016 games
drwxr-xr-x. 2 root root  6 Nov  5  2016 include
drwxr-xr-x. 2 root root  6 Nov  5  2016 lib
drwxr-xr-x. 2 root root  6 Nov  5  2016 lib64
drwxr-xr-x. 2 root root  6 Nov  5  2016 libexec
lrwxrwxrwx  1 root root 46 Nov 21 01:28 mysql -> /mariadb/mariadb-10.3.11-linux-systemd-x86_64/
drwxr-xr-x. 2 root root  6 Nov  5  2016 sbin
drwxr-xr-x. 5 root root 49 Nov 16 17:52 share
drwxr-xr-x. 2 root root  6 Nov  5  2016 src
[root@mysql1 local]# cd mysql
[root@mysql1 mysql]# pwd
/usr/local/mysql
[root@mysql1 mysql]# ls
bin                 docs               man           share
COPYING             EXCEPTIONS-CLIENT  mysql-test    sql-bench
COPYING.thirdparty  include            README.md     support-files
CREDITS             INSTALL-BINARY     README-wsrep
data                lib                scripts


4、修改mysql目录属性和权限
[root@mysql1 mysql]# chown -R mysql .
[root@mysql1 mysql]# chgrp -R mysql .
[root@mysql1 mysql]# ll
total 180
drwxr-xr-x  2 mysql mysql  4096 Sep 22 08:14 bin
-rw-r--r--  1 mysql mysql 17987 Nov 16 13:04 COPYING
-rw-r--r--  1 mysql mysql 86263 Nov 16 13:04 COPYING.thirdparty
-rw-r--r--  1 mysql mysql  2354 Nov 16 13:04 CREDITS
drwxrwxr-x  3 mysql mysql    18 Nov 19 15:54 data
drwxrwxr-x  2 mysql mysql    81 Nov 19 15:54 docs
-rw-r--r--  1 mysql mysql  8245 Nov 16 13:04 EXCEPTIONS-CLIENT
drwxrwxr-x  3 mysql mysql    19 Nov 19 15:54 include
-rw-r--r--  1 mysql mysql  8694 Nov 16 13:04 INSTALL-BINARY
drwxr-xr-x  5 mysql mysql  4096 Sep 22 22:14 lib
drwxrwxr-x  4 mysql mysql    30 Nov 19 15:54 man
drwxrwxr-x  9 mysql mysql  4096 Nov 19 15:54 mysql-test
-rw-r--r--  1 mysql mysql  2469 Nov 16 13:04 README.md
-rw-r--r--  1 mysql mysql 19510 Nov 16 13:04 README-wsrep
drwxrwxr-x  2 mysql mysql    30 Nov 19 15:54 scripts
drwxrwxr-x 32 mysql mysql  4096 Nov 19 15:54 share
drwxrwxr-x  4 mysql mysql  4096 Nov 19 15:54 sql-bench
drwxrwxr-x  4 mysql mysql   180 Nov 19 15:54 support-files
[root@mysql1 mysql]#
[root@mysql1 mysql]#


5、执行安装程序。
[root@mysql1 mysql]# cd scripts
[root@mysql1 scripts]# ls
mysql_install_db
[root@mysql1 scripts]#
[root@mysql1 scripts]# cd ..
[root@mysql1 mysql]# ./scripts/mysql_install_db --user=mysql
Installing MariaDB/MySQL system tables in '/var/lib/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 mysql1 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='/var/lib/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/

[root@mysql1 mysql]#cd


6、在系统配置文件/etc/profile和/.bash_profile里修改PATH变量,增加mysql执行文件目录
[root@mysql1 ~]# vi /etc/profile
PATH=$PATH:/usr/local/mysql/bin
export PATH                                                                               
[root@mysql1 ~]#
[root@mysql1 ~]# vi /root/.bash_profile
PATH=$PATH:$HOME/bin:/usr/local/mysql/bin
export PATH
[root@mysql1 ~]#
[root@mysql1 ~]#
[root@mysql1 ~]# exit
logout

Last login: Wed Nov 21 01:36:08 2018 from 192.168.0.18
[root@mysql1 ~]# echo $PATH
/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin:/usr/local/mysql/bin
[root@mysql1 ~]#
[root@mysql1 ~]#

 

7、启动mysql连接程序,有ERROR 2002 (HY000)报错,处理报错,修改/etc/my.cnf文件内容。
[root@mysql1 ~]#
[root@mysql1 ~]# mysql -u root -p
Enter password:
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2)
[root@mysql1 ~]#
[root@mysql1 ~]# find / -name mysql.sock
/var/lib/mysql/mysql.sock  
[root@mysql1 ~]# cd /var/lib/mysql
[root@mysql1 mysql]#
[root@mysql1 mysql]# ll
total 122932
-rw-rw---- 1 mysql mysql    16384 Nov 21 01:30 aria_log.00000001
-rw-rw---- 1 mysql mysql       52 Nov 21 01:30 aria_log_control
-rw-rw---- 1 mysql mysql      972 Nov 21 01:30 ib_buffer_pool
-rw-rw---- 1 mysql mysql 12582912 Nov 21 01:30 ibdata1
-rw-rw---- 1 mysql mysql 50331648 Nov 21 01:59 ib_logfile0
-rw-rw---- 1 mysql mysql 50331648 Nov 21 01:30 ib_logfile1
-rw-rw---- 1 mysql mysql 12582912 Nov 21 01:59 ibtmp1
drwx------ 2 mysql root      4096 Nov 21 01:30 mysql
srwxrwxrwx 1 mysql mysql        0 Nov 21 01:59 mysql.sock
drwx------ 2 mysql mysql       20 Nov 21 01:30 performance_schema
-rw-rw---- 1 mysql mysql    24576 Nov 21 01:59 tc.log
drwx------ 2 mysql mysql       20 Nov 21 01:30 test
[root@mysql1 mysql]# mysql -u root -p -S /var/lib/mysql/mysql.sock
Enter password:
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (111)
[root@mysql1 mysql]# cd /etc
[root@mysql1 etc]#                         
[root@mysql1 etc]# cp my.cnf my.cnf.bak
[root@mysql1 etc]# cat my.cnf

[mysqld]
datadir=/usr/local/mysql/data
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
                                                                            
[root@mysql1 etc]#
[root@mysql1 etc]# vi my.cnf

[mysqld]
#datadir=/var/lib/mysql/data
#socket=/var/lib/mysql/mysql.sock
datadir=/mysqldata
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

~                                                                               
~                                                                               
"my.cnf" 21L, 635C written
[root@mysql1 etc]#
[root@mysql1 etc]#
[root@mysql1 etc]# cd /usr/local/mysql
[root@mysql1 mysql]# ls
bin                 docs               man           share
COPYING             EXCEPTIONS-CLIENT  mysql-test    sql-bench
COPYING.thirdparty  include            README.md     support-files
CREDITS             INSTALL-BINARY     README-wsrep
data                lib                scripts
[root@mysql1 mysql]#

 

8、cp support-files/mysql.server到/etc/init.d/mysqld,创建mysqld服务文件,并修改服务启动设置以及rc.local文件,并尝试启动mysqld服务。
[root@mysql1 mysql]#
[root@mysql1 mysql]# ls
bin                 docs               man           share
COPYING             EXCEPTIONS-CLIENT  mysql-test    sql-bench
COPYING.thirdparty  include            README.md     support-files
CREDITS             INSTALL-BINARY     README-wsrep
data                lib                scripts
[root@mysql1 mysql]# cd support-files
[root@mysql1 support-files]# ll
total 36
-rwxr-xr-x 1 root mysql  1153 Nov 16 14:45 binary-configure
-rw-r--r-- 1 root mysql  1328 Nov 16 13:04 magic
-rwxr-xr-x 1 root mysql  1564 Nov 16 14:45 mysqld_multi.server
-rwxr-xr-x 1 root mysql   918 Nov 16 14:45 mysql-log-rotate
-rwxr-xr-x 1 root mysql 12166 Nov 16 14:45 mysql.server
drwxrwxr-x 4 root mysql    37 Nov 19 15:54 policy
drwxrwxr-x 2 root mysql    88 Nov 19 15:54 systemd
-rw-r--r-- 1 root mysql  3479 Nov 16 14:45 wsrep.cnf
-rwxr-xr-x 1 root mysql  2230 Nov 16 14:45 wsrep_notify
[root@mysql1 support-files]# cp mysql.server /etc/init.d/mysqld
[root@mysql1 support-files]# chmod 755 /etc/init.d/mysqld
[root@mysql1 support-files]# chkconfig

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]'.

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
[root@mysql1 support-files]# chkconfig --add mysqld
[root@mysql1 support-files]# chkconfig mysqld on
[root@mysql1 support-files]# chkconfig --levels 245 mysqld off
[root@mysql1 support-files]# cd /etc
[root@mysql1 etc]# cat rc.local
#!/bin/bash
# THIS FILE IS ADDED FOR COMPATIBILITY PURPOSES
#
# It is highly advisable to create own systemd services or udev rules
# to run scripts during boot instead of using this file.
#
# In contrast to previous versions due to parallel execution during boot
# this script will NOT be run after all other services.
#
# Please note that you must run 'chmod +x /etc/rc.d/rc.local' to ensure
# that this script will be executed during boot.

touch /var/lock/subsys/local
[root@mysql1 etc]#
[root@mysql1 etc]# vi rc.local

#!/bin/bash
# THIS FILE IS ADDED FOR COMPATIBILITY PURPOSES
#
# It is highly advisable to create own systemd services or udev rules
# to run scripts during boot instead of using this file.
#
# In contrast to previous versions due to parallel execution during boot
# this script will NOT be run after all other services.
#
# Please note that you must run 'chmod +x /etc/rc.d/rc.local' to ensure
# that this script will be executed during boot.

touch /var/lock/subsys/local
/usr/local/mysql/bin/mysqld_safe --user=mysql --datadir=/mysqldata/ &
~                                                                               
~                                                                               
~                                                                               
~                                                                               
~                                                                               
~                                                                               
~                                                                               
~                                                                               
~                                                                               
"rc.local" 14L, 554C written
[root@mysql1 etc]# service mysqld start
Starting mysqld (via systemctl):                           [  OK  ]
[root@mysql1 etc]# netstat -tn|grep 3306
[root@mysql1 etc]#
[root@mysql1 etc]# ps -ef|grep mysql
avahi      832     1  0 01:16 ?        00:00:00 avahi-daemon: running [mysql1.local]
root      4521     1  0 02:44 ?        00:00:00 /bin/sh /usr/local/mysql/bin/mysqld_safe --datadir=/usr/local/mysql/data --pid-file=/usr/local/mysql/data/mysql1.pid
mysql     4603  4521  0 02:44 ?        00:00:00 /usr/local/mysql/bin/mysqld --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data --plugin-dir=/usr/local/mysql/lib/plugin --user=mysql --log-error=/var/log/mariadb/mariadb.log --pid-file=/usr/local/mysql/data/mysql1.pid --socket=/var/lib/mysql/mysql.sock
root      4640  2121  0 02:45 pts/0    00:00:00 grep --color=auto mysql
[root@mysql1 etc]#
[root@mysql1 etc]# cd ..


9、创建mysql数据文件目录,并重新执行mysql安装程序。
[root@mysql1 /]# ls
bin   Centos_local  etc   lib    mariadb  mnt  proc  run   srv  tmp  var
boot  dev           home  lib64  media    opt  root  sbin  sys  usr
[root@mysql1 /]# mkdir mysqldata
[root@mysql1 /]# chown -R mysql ./mysqldata
[root@mysql1 /]# chgrp -R mysql ./mysqldata
[root@mysql1 /]#
[root@mysql1 /]# cd /usr/local/mysql/scripts
[root@mysql1 scripts]#
[root@mysql1 scripts]# ./mysql_install_db  --user=mysql --basedir=/usr/local/mysql/ --ldata=/mysqldata
Installing MariaDB/MySQL system tables in '/mysqldata' ...
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:

'/usr/local/mysql//bin/mysqladmin' -u root password 'new-password'
'/usr/local/mysql//bin/mysqladmin' -u root -h mysql1 password 'new-password'

Alternatively you can run:
'/usr/local/mysql//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.


[root@mysql1 scripts]# cd
[root@mysql1 ~]#
[root@mysql1 ~]# cd /
[root@mysql1 /]# ll
total 28
lrwxrwxrwx.   1 root  root     7 Nov 16 17:52 bin -> usr/bin
dr-xr-xr-x.   5 root  root  4096 Nov 16 17:55 boot
drwxr-xr-x.   8 root  root   220 Nov 19 12:27 Centos_local
drwxr-xr-x   19 root  root  3160 Nov 21 01:17 dev
drwxr-xr-x. 142 root  root  8192 Nov 21 02:47 etc
drwxr-xr-x.   3 root  root    19 Nov 21 01:27 home
lrwxrwxrwx.   1 root  root     7 Nov 16 17:52 lib -> usr/lib
lrwxrwxrwx.   1 root  root     9 Nov 16 17:52 lib64 -> usr/lib64
drwxr-xr-x    5 root  root   132 Nov 21 01:22 mariadb
drwxr-xr-x.   2 root  root     6 Nov  5  2016 media
drwxr-xr-x.   2 root  root     6 Nov  5  2016 mnt
drwxr-xr-x    5 mysql mysql  181 Nov 21 02:50 mysqldata
drwxr-xr-x.   3 root  root    16 Nov 20 16:32 opt
dr-xr-xr-x  138 root  root     0 Nov 21 01:16 proc
dr-xr-x---.  13 root  root  4096 Nov 21 01:36 root
drwxr-xr-x   39 root  root  1220 Nov 21 02:20 run
lrwxrwxrwx.   1 root  root     8 Nov 16 17:52 sbin -> usr/sbin
drwxr-xr-x.   2 root  root     6 Nov  5  2016 srv
dr-xr-xr-x   13 root  root     0 Nov 21 01:16 sys
drwxrwxrwt.  23 root  root  4096 Nov 21 02:50 tmp
drwxr-xr-x.  13 root  root   155 Nov 16 17:52 usr
drwxr-xr-x.  22 root  root  4096 Nov 20 17:14 var
[root@mysql1 /]# cd mysqldata
[root@mysql1 mysqldata]# ll
total 110620
-rw-rw---- 1 mysql mysql    16384 Nov 21 02:50 aria_log.00000001
-rw-rw---- 1 mysql mysql       52 Nov 21 02:50 aria_log_control
-rw-rw---- 1 mysql mysql      970 Nov 21 02:50 ib_buffer_pool
-rw-rw---- 1 mysql mysql 12582912 Nov 21 02:50 ibdata1
-rw-rw---- 1 mysql mysql 50331648 Nov 21 02:50 ib_logfile0
-rw-rw---- 1 mysql mysql 50331648 Nov 21 02:49 ib_logfile1
drwx------ 2 mysql root      4096 Nov 21 02:50 mysql
drwx------ 2 mysql mysql       20 Nov 21 02:50 performance_schema
drwx------ 2 mysql mysql       20 Nov 21 02:50 test
[root@mysql1 mysqldata]# cd
[root@mysql1 ~]#
[root@mysql1 ~]#
[root@mysql1 ~]# service mysqld restart
Restarting mysqld (via systemctl):                         [  OK  ]
[root@mysql1 ~]#
[root@mysql1 ~]#
[root@mysql1 ~]#
[root@mysql1 ~]# service mysqld stop
Stopping mysqld (via systemctl):                           [  OK  ]
[root@mysql1 ~]# service mysqld start
Starting mysqld (via systemctl):                           [  OK  ]
[root@mysql1 ~]#
[root@mysql1 ~]#
[root@mysql1 ~]# netstat -tn|grep 3306
[root@mysql1 ~]#
[root@mysql1 ~]# mysql -u root -p
Enter password:
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 11
Server version: 10.3.11-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)]> exit
Bye
[root@mysql1 ~]#

你可能感兴趣的:(Linux,Mysql)