編譯安裝過程
(1) 準(zhǔn)備用戶
groupadd -r -g 27 mysql
useradd -r -g 27 -u 27 -s /sbin/nologin mysql
(2) 準(zhǔn)備數(shù)據(jù)目錄 以/mariadb為例,建議使用邏輯卷
mkdir /mariadb
chown mysql:mysql /mariadb
(3) 準(zhǔn)備源碼包江锨,下載并解壓
wget https://mirrors.tuna.tsinghua.edu.cn/mariadb//mariadb-5.5.59/source/mariadb-5.5.59.tar.gz
tar xvf mariadb-5.5.59.tar.gz -C /root/
cd /root
(4)編譯環(huán)境準(zhǔn)備
首先安裝/更新一些編譯時(shí)會(huì)用到的基礎(chǔ)包
[root@localhost local]# yum -y install gcc gcc-c++ make cmake ncurses ncurses-devel libxml2 libxml2-devel openssl-devel bison bison-deve
mkdir /etc/mariadb //存放主配置文件的目錄
mkdir /usr/local/mariadb //存放編譯好的二進(jìn)制程序目錄
(5)編譯安裝
cmake . \
-DCMAKE_INSTALL_PREFIX=/usr/local/mariadb \
-DMYSQL_DATADIR=/mariadb \
-DSYSCONFDIR=/etc/mariadb \
-DMYSQL_USER=mysql \
-DWITH_INNOBASE_STORAGE_ENGINE=1 \
-DWITH_ARCHIVE_STORAGE_ENGINE=1 \
-DWITH_BLACKHOLE_STORAGE_ENGINE=1 \
-DWITH_READLINE=1 \
-DWITH_SSL=system \
-DWITH_ZLIB=system \
-DWITH_LIBWRAP=0 \
-DMYSQL_UNIX_ADDR=/mariadb/mysql.sock \
-DDEFAULT_CHARSET=utf8 \
-DDEFAULT_COLLATION=utf8_general_ci \
-DENABLED_LOCAL_INFILE=1 \
-DWITH_PARTITION_STORAGE_ENGINE=1 \
-DWITH_DEBUG=0 \
-DWITHOUT_MROONGA_STORAGE_ENGINE=1
make && make install
chown -R root:mysql /usr/local/mariadb
錯(cuò)誤集錦:
如果在make過程中出如下錯(cuò)矛辕,可考慮一下是內(nèi)存問題,1G內(nèi)存沒開swap編譯出錯(cuò)
如果make報(bào)錯(cuò)
錯(cuò)誤信息:mysqld.cc: In function ‘void handle_connections_sockets()’
主要是沒有安裝libmcrypt相關(guān)的包,直接使用yum install libmcrypt* -y安裝完成后侯勉,在重新編譯在編譯出現(xiàn)異常,在重新編譯的時(shí)候鹿寻,需要先刪除mysql目錄下cmakecache.txt再重新編譯娱挨。
(6)編譯好的程序目錄導(dǎo)入至PATH環(huán)境變量中
編輯文件
vim /etc/profile.d/mariadb.sh
export PATH=/usr/local/mariadb/bin:$PATH
(7)導(dǎo)入幫助手冊(cè)
編輯文件
vim /etc/man.config|man_db.conf
MANPATH_MAP /usr/local/mariadb/bin /usr/local/mariadb/man //添加此行
更新man數(shù)據(jù)庫
mandb
(8) 準(zhǔn)備配置文件配置格式
cd /usr/local/mariadb/
cp -a support-files/support-files/my-innodb-heavy-4G.cnf /etc/mariadb/my.cnf
[client]中添加一個(gè)選項(xiàng)
safe_updates
[mysqld]中添加三個(gè)選項(xiàng):
datadir = /mariadb
innodb_file_per_table = on
skip_name_resolve = on 禁止主機(jī)名解析,建議使用
(9)初始化數(shù)據(jù)庫醉途,創(chuàng)建數(shù)據(jù)庫文件
cd /usr/local/mariadb/
./scripts/mysql_install_db --datadir=/mariadb --user=mysql
(10)準(zhǔn)備日志文件
touch /var/log/mysqld.log
chown mysql /var/log/mysqld.log
(11)準(zhǔn)備服務(wù)腳本矾瑰,并啟動(dòng)服務(wù)
cd /usr/local/mariadb/
cp ./support-files/mysql.server /etc/rc.d/init.d/mariadb
cd /etc/rc.d/init.d/
chkconfig --add mariadb
service mariadb start
(12)安全初始化
[root@wangshuai mariadb]#mysql_secure_installation
/usr/local/mariadb/bin/mysql_secure_installation: line 393: find_mysql_client: command not found
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): //當(dāng)前數(shù)據(jù)庫密碼為空,直接敲擊回車隘擎。
OK, successfully used password, moving on...
Setting the root password ensures that nobody can log into the MariaDB
root user without the proper authorisation.
You already have a root password set, so you can safely answer 'n'.
Set root password? [Y/n] y
New password: //輸入要為root用戶設(shè)置的數(shù)據(jù)庫密碼殴穴。
Re-enter new password: //重復(fù)再輸入一次密碼。
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 //(刪除匿名帳號(hào))
... 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 //(禁止root用戶從遠(yuǎ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 //(刪除test數(shù)據(jù)庫并取消對(duì)其的訪問權(quán)限)
- 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 //(刷新授權(quán)表货葬,讓初始化后的設(shè)定立即生效)
... 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@wangshuai mariadb]#
(13)登陸測(cè)試
[root@wangshuai ~]#mysql -uroot -p
Enter password:
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection id is 22
Server version: 5.5.59-MariaDB Source distribution
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.01 sec)
MariaDB [(none)]> exit
Bye
[root@wangshuai ~]#