Oracle Linux 7.1中安裝Mariadb

eric0435發表於2019-06-04

在Oracle Linux 7.1中安裝Mariadb 10.0.38,因為Mariadb是Mysql的分支,安裝操作基本類似。

1.首先下載安裝介質mariadb-10.0.38-linux-glibc_214-x86.tar.gz 並將其上傳到伺服器的/soft目錄

2.建立使用者與使用者組

[root@cs1 soft]# groupadd mysql


[root@cs1 soft]# useradd -g mysql mysql

3.將介質解壓到/usr/local/目錄下

[root@cs1 soft]# cd /usr/local


[root@cs1 local]# gunzip < /soft/mariadb-10.0.38-linux-glibc_214-x86.tar.gz | tar xvf -

mariadb-10.0.38-linux-glibc_214-x86/

mariadb-10.0.38-linux-glibc_214-x86/man/

mariadb-10.0.38-linux-glibc_214-x86/man/man8/

mariadb-10.0.38-linux-glibc_214-x86/man/man8/mysqld.8

........省略..........


[root@cs1 local]# ls -lrt

總用量 4

drwxr-xr-x.  2 root root    6 5月   8 2014 src

drwxr-xr-x.  2 root root    6 5月   8 2014 sbin

drwxr-xr-x.  2 root root    6 5月   8 2014 libexec

drwxr-xr-x.  2 root root    6 5月   8 2014 libdrwxr-xr-x.  2 root root    6 5月   8 2014 lib

drwxr-xr-x.  2 root root    6 5月   8 2014 include

drwxr-xr-x.  2 root root    6 5月   8 2014 games

drwxr-xr-x.  2 root root    6 5月   8 2014 etc

drwxr-xr-x.  5 root root   46 10月 12 2017 share

drwxr-xr-x.  2 root root   46 3月   9 2018 bin

drwxrwxr-x  13 1021 1004 4096 1月  31 02:40 mariadb-10.0.38-linux-glibc_214-x86

4.建立軟連結

[root@cs1 local]# ln -s mariadb-10.0.38-linux-glibc_214-x86 mysql

[root@cs1 local]# ls -lrt

總用量 4

drwxr-xr-x.  2 root root    6 5月   8 2014 src

drwxr-xr-x.  2 root root    6 5月   8 2014 sbin

drwxr-xr-x.  2 root root    6 5月   8 2014 libexec

drwxr-xr-x.  2 root root    6 5月   8 2014 libdrwxr-xr-x.  2 root root    6 5月   8 2014 lib

drwxr-xr-x.  2 root root    6 5月   8 2014 include

drwxr-xr-x.  2 root root    6 5月   8 2014 games

drwxr-xr-x.  2 root root    6 5月   8 2014 etc

drwxr-xr-x.  5 root root   46 10月 12 2017 share

drwxr-xr-x.  2 root root   46 3月   9 2018 bin

drwxrwxr-x  13 1021 1004 4096 1月  31 02:40 mariadb-10.0.38-linux-glibc_214-x86 

lrwxrwxrwx   1 root root   38 6月   4 14:43 mysql -> mariadb-10.0.38-linux-glibc_214-x86

5.確保目錄mysql能夠被使用者mysql訪問

[root@cs1 local]# cd mysql

[root@cs1 mysql]# chown -R mysql .

[root@cs1 mysql]# chgrp -R mysql .

6.在安裝Mariadb之前,必須建立Mariadb存放資料的目錄並初始化grant表,執行mysql_install_db命令來安裝Mariadb,如果使用root使用者來執行,必須包含--user選項來指定使用者,如果是mysql使用者來執行可以忽略--user選項。使用 --basedir=path 選項指定Mariadb安裝目錄的路徑,--datadir=path選項指定Mariadb資料目錄的路徑。如果沒有指定--basedir與--datadir選項它們在/usr/local/mysql目錄下建立一個data目錄。

[root@cs1 mysql]# scripts/mysql_install_db --user=mysql

Installing MariaDB/MySQL system tables in './data' ...

190604 14:44:44 [Note] ./bin/mysqld (mysqld 10.0.38-MariaDB) starting as process 19627 ...

190604 14:44:45 [Note] InnoDB: innodb_empty_free_list_algorithm has been changed to legacy because of small buffer pool size. In order to use backoff, increase buffer pool at least up to 20MB.


190604 14:44:45 [Note] InnoDB: Using mutexes to ref count buffer pool pages

190604 14:44:45 [Note] InnoDB: The InnoDB memory heap is disabled

190604 14:44:45 [Note] InnoDB: Mutexes and rw_locks use GCC atomic builtins

190604 14:44:45 [Note] InnoDB: GCC builtin __atomic_thread_fence() is used for memory barrier

190604 14:44:45 [Note] InnoDB: Compressed tables use zlib 1.2.11

190604 14:44:45 [Note] InnoDB: Using Linux native AIO

190604 14:44:45 [Note] InnoDB: Using CPU crc32 instructions

190604 14:44:45 [Note] InnoDB: Initializing buffer pool, size = 128.0M

190604 14:44:45 [Note] InnoDB: Completed initialization of buffer pool

190604 14:44:45 [Note] InnoDB: The first specified data file ./ibdata1 did not exist: a new database to be created!

190604 14:44:45 [Note] InnoDB: Setting file ./ibdata1 size to 12 MB

190604 14:44:45 [Note] InnoDB: Database physically writes the file full: wait...

190604 14:44:45 [Note] InnoDB: Setting log file ./ib_logfile101 size to 48 MB

190604 14:44:45 [Note] InnoDB: Setting log file ./ib_logfile1 size to 48 MB

190604 14:44:46 [Note] InnoDB: Renaming log file ./ib_logfile101 to ./ib_logfile0

190604 14:44:46 [Warning] InnoDB: New log files created, LSN=45781

190604 14:44:46 [Note] InnoDB: Doublewrite buffer not found: creating new

190604 14:44:46 [Note] InnoDB: Doublewrite buffer created

190604 14:44:46 [Note] InnoDB: 128 rollback segment(s) are active.

190604 14:44:46 [Warning] InnoDB: Creating foreign key constraint system tables.

190604 14:44:46 [Note] InnoDB: Foreign key constraint system tables created

190604 14:44:46 [Note] InnoDB: Creating tablespace and datafile system tables.

190604 14:44:46 [Note] InnoDB: Tablespace and datafile system tables created.

190604 14:44:46 [Note] InnoDB: Waiting for purge to start

190604 14:44:46 [Note] InnoDB:  Percona XtraDB () 5.6.42-84.2 started; log sequence number 0

190604 14:44:48 [Note] InnoDB: FTS optimize thread exiting.

190604 14:44:48 [Note] InnoDB: Starting shutdown...

190604 14:44:48 [Note] InnoDB: Waiting for page_cleaner to finish flushing of buffer pool

190604 14:44:50 [Note] InnoDB: Shutdown completed; log sequence number 1616697

OK

Filling help tables...

190604 14:44:50 [Note] ./bin/mysqld (mysqld 10.0.38-MariaDB) starting as process 19661 ...

190604 14:44:50 [Note] InnoDB: innodb_empty_free_list_algorithm has been changed to legacy because of small buffer pool size. In order to use backoff, increase buffer pool at least up to 20MB.


190604 14:44:50 [Note] InnoDB: Using mutexes to ref count buffer pool pages

190604 14:44:50 [Note] InnoDB: The InnoDB memory heap is disabled

190604 14:44:50 [Note] InnoDB: Mutexes and rw_locks use GCC atomic builtins

190604 14:44:50 [Note] InnoDB: GCC builtin __atomic_thread_fence() is used for memory barrier

190604 14:44:50 [Note] InnoDB: Compressed tables use zlib 1.2.11

190604 14:44:50 [Note] InnoDB: Using Linux native AIO

190604 14:44:50 [Note] InnoDB: Using CPU crc32 instructions

190604 14:44:50 [Note] InnoDB: Initializing buffer pool, size = 128.0M

190604 14:44:50 [Note] InnoDB: Completed initialization of buffer pool

190604 14:44:50 [Note] InnoDB: Highest supported file format is Barracuda.

190604 14:44:50 [Note] InnoDB: 128 rollback segment(s) are active.

190604 14:44:50 [Note] InnoDB: Waiting for purge to start

190604 14:44:50 [Note] InnoDB:  Percona XtraDB () 5.6.42-84.2 started; log sequence number 1616697

190604 14:44:50 [Note] InnoDB: FTS optimize thread exiting.

190604 14:44:50 [Note] InnoDB: Starting shutdown...

190604 14:44:51 [Note] InnoDB: Waiting for page_cleaner to finish flushing of buffer pool

190604 14:44:53 [Note] InnoDB: Shutdown completed; log sequence number 1616707

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 cs1.jy.net 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 or the

MySQL manual for more instructions.


You can start the MariaDB daemon with:

cd '.' ; ./bin/mysqld_safe --datadir='./data'


You can test the MariaDB daemon with mysql-test-run.pl

cd './mysql-test' ; perl mysql-test-run.pl


Please report any problems at


The latest information about MariaDB is available at

You can find additional information about the MySQL part at:

http://dev.mysql.com

Consider joining MariaDB's strong and vibrant community:

7.因為安裝Mariadb的使用者是root使用者,而data目錄必須要被mysql使用者訪問,因此修改data目錄的使用者與組許可權

[root@cs1 mysql]# chown -R root .

[root@cs1 mysql]# chown -R mysql data

8.在安裝完成後來測試Mariadb的啟動

[root@cs1 mysql]# bin/mysqld_safe --user=mysql &

[1] 19770

[root@cs1 mysql]# 190604 14:45:25 mysqld_safe Logging to '/usr/local/mysql/data/cs1.jy.net.err'.

190604 14:45:25 mysqld_safe Starting mysqld daemon with databases from /usr/local/mysql/data

mysqld_safe是服務端工具,用於啟動mysqld,並且是mysqld的守護程式,mysqld_safe加&在後臺執行$BASEDIR/bin/mysqld_safe &。因為mysqld_safe是mysqld的守護程式,所以mysqld_safe指令碼會在啟動MySQL伺服器後繼續監控其執行情況,並在其當機時重新啟動它。直接使用mysqld_safe啟動mysqld時,mysqld_safe可以使用引數選項見mysqld_safe --help,此時可以使用其他配置檔案,相當於mysqld_safe把引數傳遞給mysqld。mysql.server指令碼其實也是呼叫mysqld_safe指令碼去啟動MySQL伺服器的,但此時mysqld_safe不能使用引數選項即不能mysqld_safe --defaults-file這樣的模式。

9.將啟動Mariadb的指令碼配置成服務透過service name start命令來啟用

[root@cs1 mysql]# cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld

[root@cs1 mysql]# cat /etc/init.d/mysqld


[root@cs1 Packages]# service mysqld status

 SUCCESS! MariaDB running (19839)

[root@cs1 Packages]# service mysqld stop

Shutting down MariaDB... SUCCESS! 

[root@cs1 Packages]# service mysqld start

Starting MariaDB.190604 18:26:04 mysqld_safe Logging to '/usr/local/mysql/data/cs1.jy.net.err'.

190604 18:26:05 mysqld_safe Starting mysqld daemon with databases from /usr/local/mysql/data

 SUCCESS!

10.修改root使用者密碼

-bash-4.2$ mysql

Welcome to the MariaDB monitor.  Commands end with ; or \g.

Your MariaDB connection id is 4

Server version: 10.0.38-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 [mysql]> set password=password("123456");

Query OK, 0 rows affected (0.00 sec)


MariaDB [mysql]> exit


-bash-4.2$ mysql -u root -p

Enter password: 

Welcome to the MariaDB monitor.  Commands end with ; or \g.

Your MariaDB connection id is 6

Server version: 10.0.38-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 |

| test               |

+--------------------+

4 rows in set (0.01 sec)


MariaDB [(none)]> use mysql;

Reading table information for completion of table and column names

You can turn off this feature to get a quicker startup with -A


Database changed

11.使用mytop工具來監控Mariadb,mytop在Mariadb安裝時也會自動安裝,而mysql中需要單獨安裝

-bash-4.2$ mytop --prompt -u root -d mysql

Password: 

install_driver(mysql) failed: Can't locate DBD/mysql.pm in @INC (@INC contains: /usr/local/lib/perl5 /usr/local/share/perl5 /usr/lib/perl5/vendor_perl /usr/share/perl5/vendor_perl /usr/lib/perl5 /usr/share/perl5 .) at (eval 13) line 3,  line 1.

Perhaps the DBD::mysql perl module hasn't been fully installed,

or perhaps the capitalisation of 'mysql' isn't right.

Available drivers: DBM, ExampleP, File, Gofer, Proxy, SQLite, Sponge.

 at /usr/local/mysql//bin/mytop line 253.

錯誤資訊說明沒有安裝perl-DBD-MySQL工具包

12.安裝perl-DBD-MySQ工具包

[root@cs1 bin]# yum install perl-DBD-MySQL

已載入外掛:langpacks

Repodata is over 2 weeks old. Install yum-cron? Or run: yum makecache fast

file:///run/media/jy/OL-7.1%20Server.x86/repodata/repomd.xml: [Errno 14] curl#37 - "Couldn't open file /run/media/jy/OL-7.1%20Server.x86/repodata/repomd.xml"

正在嘗試其它映象。

正在解決依賴關係

--> 正在檢查事務

---> 軟體包 perl-DBD-MySQL.x86.0.4.023-5.0.1.el7 將被 安裝

--> 正在處理依賴關係 libmysqlclient.so.18(libmysqlclient_18)(bit),它被軟體包 perl-DBD-MySQL-4.023-5.0.1.el7.x86 需要

--> 正在處理依賴關係 libmysqlclient.so.18()(bit),它被軟體包 perl-DBD-MySQL-4.023-5.0.1.el7.x86 需要

--> 正在檢查事務

---> 軟體包 mysql-community-libs.x86.0.5.6.23-3.el7 將被 安裝

--> 正在處理依賴關係 mysql-community-common(x86-) = 5.6.23-3.el7,它被軟體包 mysql-community-libs-5.6.23-3.el7.x86 需要

--> 正在檢查事務

---> 軟體包 mysql-community-common.x86.0.5.6.23-3.el7 將被 安裝

--> 解決依賴關係完成


依賴關係解決


============================================================================================================================================================================================================================================

 Package                                                            架構                                               版本                                                         源                                                 大小

============================================================================================================================================================================================================================================

正在安裝:

 perl-DBD-MySQL                                                     x86                                             4.023-5.0.1.el7                                              local                                             140 k

為依賴而安裝:

 mysql-community-common                                             x86                                             5.6.23-3.el7                                                 local                                             256 k

 mysql-community-libs                                               x86                                             5.6.23-3.el7                                                 local                                             2.0 M


事務概要

============================================================================================================================================================================================================================================

安裝  1 軟體包 (+2 依賴軟體包)


總下載量:2.4 M

安裝大小:12 M

Is this ok [y/d/N]: y

Downloading packages:



Error downloading packages:

  mysql-community-common-5.6.23-3.el7.x86: [Errno 256] No more mirrors to try.

  perl-DBD-MySQL-4.023-5.0.1.el7.x86: [Errno 256] No more mirrors to try.

  mysql-community-libs-5.6.23-3.el7.x86: [Errno 256] No more mirrors to try.

出現不能下載相關工具包的錯誤

13.將作業系統ISO檔案掛載到系統中並進入Packages目錄執行rpm命令來安裝

root@cs1 Packages]# ls -lrt mysql*

-rw-rw-r-- 1 root root  13136 5月  14 2014 mysql-connector-java-5.1.25-3.el7.noarch.rpm

-rw-rw-r-- 1 root root   145144 8月   6 2014 mysql-connector-odbc-5.2.5-6.0.1.el7.x86.rpm

-rw-r--r-- 1 root root   4203 2月  19 2015 mysql-community-bench-5.6.23-3.el7.x86.rpm

-rw-r--r-- 1 root root 19378376 2月  19 2015 mysql-community-client-5.6.23-3.el7.i686.rpm

-rw-r--r-- 1 root root  3435828 2月  19 2015 mysql-community-devel-5.6.23-3.el7.i686.rpm

-rw-r--r-- 1 root root   2624 2月  19 2015 mysql-community-common-5.6.23-3.el7.x86.rpm

-rw-r--r-- 1 root root   262516 2月  19 2015 mysql-community-common-5.6.23-3.el7.i686.rpm

-rw-r--r-- 1 root root 19979168 2月  19 2015 mysql-community-client-5.6.23-3.el7.x86.rpm

-rw-r--r-- 1 root root  3543424 2月  19 2015 mysql-community-devel-5.6.23-3.el7.x86.rpm

-rw-r--r-- 1 root root 23060740 2月  19 2015 mysql-community-embedded-5.6.23-3.el7.i686.rpm

-rw-r--r-- 1 root root 23733580 2月  19 2015 mysql-community-embedded-5.6.23-3.el7.x86.rpm

-rw-r--r-- 1 root root 4916 2月  19 2015 mysql-community-embedded-devel-5.6.23-3.el7.i686.rpm

-rw-r--r-- 1 root root  2104968 2月  19 2015 mysql-community-libs-5.6.23-3.el7.x86.rpm

-rw-r--r-- 1 root root  2040356 2月  19 2015 mysql-community-libs-5.6.23-3.el7.i686.rpm

-rw-r--r-- 1 root root 68058508 2月  19 2015 mysql-community-embedded-devel-5.6.23-3.el7.x86.rpm

-rw-r--r-- 1 root root 60224180 2月  19 2015 mysql-community-server-5.6.23-3.el7.x86.rpm

-rw-r--r-- 1 root root 59280136 2月  19 2015 mysql-community-test-5.6.23-3.el7.x86.rpm


[root@cs1 Packages]# rpm -ihv mysql-community-libs-5.6.23-3.el7.x86.rpm

警告:mysql-community-libs-5.6.23-3.el7.x86.rpm: 頭V3 RSA/SHA256 Signature, 金鑰 ID ec551f03: NOKEY

錯誤:依賴檢測失敗:

        mysql-community-common(x86-) = 5.6.23-3.el7 被 mysql-community-libs-5.6.23-3.el7.x86 需要

[root@cs1 Packages]# rpm -ivh mysql-community-common-5.6.23-3.el7.x86.rpm

警告:mysql-community-common-5.6.23-3.el7.x86.rpm: 頭V3 RSA/SHA256 Signature, 金鑰 ID ec551f03: NOKEY

準備中...                             ################################# [100%]

正在升級/安裝...

   1:mysql-community-common-5.6.23-3.e################################# [100%]

[root@cs1 Packages]# rpm -ihv mysql-community-libs-5.6.23-3.el7.x86.rpm

警告:mysql-community-libs-5.6.23-3.el7.x86.rpm: 頭V3 RSA/SHA256 Signature, 金鑰 ID ec551f03: NOKEY

準備中...                             ################################# [100%]

正在升級/安裝...

   1:mysql-community-libs-5.6.23-3.el7################################# [100%]


[root@cs1 Packages]# ls -lrt perl-DBD-MySQL

ls: 無法訪問perl-DBD-MySQL: 沒有那個檔案或目錄

[root@cs1 Packages]# ls -lrt perl-DBD-MySQL*

-rw-rw-r-- 1 root root 143092 8月   6 2014 perl-DBD-MySQL-4.023-5.0.1.el7.x86.rpm

[root@cs1 Packages]# rpm -ivh perl-DBD-MySQL-4.023-5.0.1.el7.x86.rpm

警告:perl-DBD-MySQL-4.023-5.0.1.el7.x86.rpm: 頭V3 RSA/SHA256 Signature, 金鑰 ID ec551f03: NOKEY

準備中...                             ################################# [100%]

正在升級/安裝...

   1:perl-DBD-MySQL-4.023-5.0.1.el7   ################################# [100%]

14.執行mytop命令來監控Mariadb

-bash-4.2$ mytop -u root -p 123456

MariaDB on localhost (10.0.38-MariaDB)                                                                                                                                                                  up 0+01:04:21 [15:49:46]

 Queries: 170.0   qps:    0 Slow:     0.0         Se/In/Up/De(%):    06/00/00/00

 Sorts:     0 qps now:    1 Slow qps: 0.0  Threads:    2 (   1/   0) 00/00/00/00

 Handler: (R/W/U/D)     0/    0/    0/    0        Tmp: R/W/U:    89/   89/    0

 ISAM Key Efficiency: 0.0%  Bps in/out:   1.4/ 66.6   Now in/out:  22.6/ 2.9k


       Id     User         Host/IP        DB   Time     %    Cmd           State Query

       --     ----         -------        --   ----     -    ---           ----- ----------

       12     root       localhost     mysql     10   0.0  Sleep                                                                                                                                                                          

       10     root       localhost      test      0   0.0  Query            init show full processlist

到此安裝也就完成了。


來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/26015009/viewspace-2646728/,如需轉載,請註明出處,否則將追究法律責任。

相關文章