编译安装过程
(1) 准备用户
groupadd -r -g 27 mysql
useradd -r -g 27 -u 27 -s /sbin/nologin mysql
(2) 准备数据目录 以/mariadb为例,建议使用逻辑卷
mkdir /mariadb
chown mysql:mysql /mariadb
(3) 准备源码包,下载并解压
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)编译环境准备
首先安装/更新一些编译时会用到的基础包
[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 //存放编译好的二进制程序目录
(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
错误集锦:
如果在make过程中出如下错,可考虑一下是内存问题,1G内存没开swap编译出错
如果make报错
错误信息:mysqld.cc: In function ‘void handle_connections_sockets()’
主要是没有安装libmcrypt相关的包,直接使用yum install libmcrypt* -y安装完成后,在重新编译在编译出现异常,在重新编译的时候,需要先删除mysql目录下cmakecache.txt再重新编译。
(6)编译好的程序目录导入至PATH环境变量中
编辑文件
vim /etc/profile.d/mariadb.sh
export PATH=/usr/local/mariadb/bin:$PATH
(7)导入帮助手册
编辑文件
vim /etc/man.config|man_db.conf
MANPATH_MAP /usr/local/mariadb/bin /usr/local/mariadb/man //添加此行
更新man数据库
mandb
(8) 准备配置文件配置格式
cd /usr/local/mariadb/
cp -a support-files/support-files/my-innodb-heavy-4G.cnf /etc/mariadb/my.cnf
[client]中添加一个选项
safe_updates
[mysqld]中添加三个选项:
datadir = /mariadb
innodb_file_per_table = on
skip_name_resolve = on 禁止主机名解析,建议使用
(9)初始化数据库,创建数据库文件
cd /usr/local/mariadb/
./scripts/mysql_install_db --datadir=/mariadb --user=mysql
(10)准备日志文件
touch /var/log/mysqld.log
chown mysql /var/log/mysqld.log
(11)准备服务脚本,并启动服务
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): //当前数据库密码为空,直接敲击回车。
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用户设置的数据库密码。
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] n //(禁止root用户从远程登陆)
... 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数据库并取消对其的访问权限)
- 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@wangshuai mariadb]#
(13)登陆测试
[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 ~]#
网友评论