当前服务器已经安装了 MySQL ,现在为 Mariadb 的安装:
解压文件
tar zxvf mariadb-10.2.8-linux-x86_64.tar.gz
mv mariadb-10.2.8-linux-x86_64 /usr/local/mariadb
cd /usr/local/mariadb
groupadd –system mariadb
useradd -c “MariaDB Server” -d /usr/local/mariadb -g mariadb –system mariadb
mkdir {logs,tmp,tokudb_data}
chown -R mariadb:mariadb .
设置配置文件
cp support-files/my-small.cnf ./my.cnf
chown -R mariadb:mariadb my.cnf
vim /etc/mariadb/my.cnf
[client]
#password = your_password
port = 3307
socket = /tmp/mariadb3307.sock
[mysql]
prompt = “MariaDB:\\u@\\h > “
default-character-set = ‘utf8’
auto-rehash = FALSE
local-infile = 1
max-allowed-packet = 64M
secure-auth = TRUE
[mysqld]
user = mariadb
server-id = 313307
port = 3307
socket = /tmp/mariadb3307.sock
basedir = /usr/local/mariadb
datadir = /usr/local/mariadb/data
log-error = /usr/local/mariadb/mariadb-err.log
tmpdir = /usr/local/mariadb/tmp
log-bin = /usr/local/mariadb/logs/mariadb-bin
binlog-format = ROW
expire-logs-days = 15
max-binlog-size = 1024M
sync-binlog = 1
log-slave-updates
skip-name-resolve
lower_case_table_names = 1
event_scheduler = 1
character-set-server = ‘utf8’
collation-server = ‘utf8_general_ci’
default-storage-engine = ‘InnoDB’
transaction-isolation = READ-COMMITTED
skip-external-locking
key_buffer_size = 64M
max_allowed_packet = 32M
innodb-flush-log-at-trx-commit = 1
innodb-buffer-pool-size = 2G
innodb-buffer-pool-instances = 2
innodb-file-per-table = 1
general_log_file = general.log
log-warnings = 2
log_error = error.log
slow-query-log = 1
slow_query_log_file = slow.log
long-query-time = 1
设置服务启动文件
cp support-files/mysql.server /etc/init.d/mariadb
chmod +x /etc/init.d/mariadb
修改服务器启动文件
vim /etc/init.d/mariadb
更改以下几处地方
vim /etc/init.d/mariadb
1.指定 basedir 及 datadir 路径,添加配置文件变量 conf,修改3处
basedir=/usr/local/mariadb
datadir=/usr/local/mariadb/data
conf=$basedir/my.cnf
2.在 start 启动服务处添加 “ –defaults-file=”$conf” ”:
$bindir/mysqld_safe --defaults-file="$conf" --datadir="$datadir" --pid-file="$mysqld_pid_file_path" "$@" &
3.在函数 wait_for_ready () 处添加 “ –defaults-file=”$conf” ”:
if $bindir/mysqladmin --defaults-file="$conf" ping >/dev/null 2>&1; then
初始化
scripts/mysql_install_db --defaults-file=/usr/local/mariadb/my.cnf --user=mariadb
Installing MariaDB/MySQL system tables in ‘/usr/local/mariadb/data’ …
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 127.0.0.1
127.0.0.1 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=’/usr/local/mariadb/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 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/
启动服务及设置开机启动
/etc/init.d/mariadb start
cd /etc/init.d
chkconfig –add mariadb
chkconfig –levels 3 mariadb on
systemctl status mariadb.service
安装前面初始化的日志提示,首先设置root密码,如设置密码为 “Fyy19940722”
cd /usr/local/mariadb
./bin/mysqladmin -uroot -hlocalhost.localdomain -P3307 password ‘Fyy19940722’
登录 mariadb 实例
mysql -uroot -hlocalhost.localdomain -P3307 -p
mysql > select host,user from mysql.user;
+———————–+——+
| host | user |
+———————–+——+
| 127.0.0.1 | root |
| ::1 | root |
| localhost | |
| localhost | root |
| localhost.localdomain | |
| localhost.localdomain | root |
+———————–+——+
整理 root 用户:
create user root@’192.168.%.%’ IDENTIFIED by ‘mariadb’;
grant all privileges on . to root@’192.168.%.%’ with grant option;
flush privileges;
drop user ‘root’@’::1′;
drop user ”@’localhost’;
drop user ”@’localhost.localdomain’;
drop user ‘root’@’localhost.localdomain’;
flush privileges;
alter user root@’localhost’ identified by ‘Fyy19940722’;
alter user root@’127.0.0.1′ identified by ‘Fyy19940722’;
grant all privileges on . to ‘root’@’%’ identified by ‘Fyy19940722’ with grant option; flush privileges;
flush privileges;