useradd -r -s /sbin/nologin -M mysql
chown -R
mysql:
三.配置
1.命令工具PATH和MAN PATH
echo 'PATH=$PATH:/opt/mariadb/bin' >>/etc/profile
source /etc/profile
echo MANPATH /opt/mariadb/man >>/etc/man.config
2.初始化mariadb
http://www.canonware.com/jemalloc/
依赖多线程内存管理
rpm
-ivh
yum -y install jemalloc
或
wget
tar -xvf jemalloc-4.0.4.tar.bz2 -C /opt
cd /opt/jemalloc-4.0.4
./configure && make -j4 && make -j4 install
ldconfig
/opt/mariadb/scripts/mysql_install_db --user=mysql --basedir=/opt/mariadb --datadir=/opt/mariadb/data
3.init脚本
cp /opt/mariadb/support-files/mysql.server /etc/init.d/mysql
chmod +x /etc/init.d/mysql
sed -i "/^basedir=/c basedir=/opt/mariadb" /etc/init.d/mysql
sed -i "/^datadir=/c datadir=/opt/mariadb/data" /etc/init.d/mysql
4.主配置文件
cp -f
[mysqld]
log-error
pid-file
在[mysqld]段增加如上两行
5.logrotate配置文件
cp -f /opt/mariadb/support-files/mysql-log-rotate /etc/logrotate.d/
四.启动
chown -R
mysql:
service mysql start
chkconfig mysql on
[root@slave2 ~]# service mysql start
Starting MySQL. SUCCESS!
[root@slave2 ~]# netstat -tunlp|grep mysql
tcp
五.安全设置
sed -i "/^basedir=/c basedir=/opt/mariadb" /opt/mariadb/bin/mysql_secure_installation
[root@slave2 ~]# mysql_secure_installation
print: /opt/mariadb/bin/my_print_defaults
NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MariaDB
In order to log into MariaDB to secure it, we'll need the current
password for the root user.
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.
Set root password? [Y/n]
New password:
Re-enter new password:
Password updated successfully!
Reloading privilege tables..
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.
go a bit smoother.
production environment.
Remove anonymous users? [Y/n]
Normally, root should only be allowed to connect from
'localhost'.
ensures that someone cannot guess at the root password from the network.
Disallow root login remotely? [Y/n]
By default, MariaDB comes with a database named 'test' that anyone can
access.
before moving into a production environment.
Remove test database and access to it? [Y/n]
Reloading the privilege tables will ensure that all changes made so far
will take effect immediately.
Reload privilege tables now? [Y/n]
Cleaning up...
All done!
installation should now be secure.
Thanks for using MariaDB!
提示:如没特殊要求,除设置root密码外,一路回车即可
六.设置默认字符集
请参看MariaDB编码问题
因为是二进制安装,所以字符集在官方release的时候就指定了,如
+--------------------------+---------------------------------------------------+
| Variable_name
+--------------------------+---------------------------------------------------+
| character_set_client
| character_set_connection | utf8
| character_set_database
| character_set_filesystem | binary
| character_set_results
| character_set_server
| character_set_system
| character_sets_dir
+--------------------------+---------------------------------------------------+
为了更好的通用性,生产更多用的是utf8,所以需要
修主配置文件/etc/my.cnf
init_connect = 'SET collation_connection = utf8_general_ci'
init_connect
=
character_set_server = utf8
collation_server = utf8_general_ci
init_connect =
init_connect =
character_set_server =
collation_server =
root@jlive:~#/etc/init.d/mysql restart
Restarting mysql (via systemctl):
MariaDB [(none)]> SHOW VARIABLES LIKE 'character_%';
+--------------------------+---------------------------------------------------+
| Variable_name
+--------------------------+---------------------------------------------------+
| character_set_client
| character_set_connection | utf8
| character_set_database
| character_set_filesystem | binary
| character_set_results
| character_set_server
| character_set_system
| character_sets_dir
+--------------------------+---------------------------------------------------+
8 rows in set (0.00 sec)
MariaDB [(none)]> SHOW VARIABLES LIKE 'collation%';
+----------------------+-----------------+
| Variable_name
+----------------------+-----------------+
| collation_connection | utf8_general_ci |
| collation_database
| collation_server
+----------------------+-----------------+
3 rows in set (0.01 sec)
七.测试
[root@slave2 ~]# mysql -uroot -p
Enter password:
Welcome to the MariaDB monitor.
Your MariaDB connection id is 13
Server version: 10.1.10-MariaDB-log MariaDB Server
Copyright (c) 2000, 2015, 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)]> show engines;
+--------------------+---------+--------------------------------------------------------------------------------------------------+--------------+------+------------+
| Engine
+--------------------+---------+--------------------------------------------------------------------------------------------------+--------------+------+------------+
| MRG_MyISAM
| CSV
| Aria
| MyISAM
| MEMORY
| InnoDB
| SEQUENCE
| PERFORMANCE_SCHEMA | YES
+--------------------+---------+--------------------------------------------------------------------------------------------------+--------------+------+------------+
8 rows in set (0.00 sec)
MariaDB [(none)]> quit
Bye