MariaDB 与 MySQL 安装在同一台服务器

当前服务器已经安装了 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
# vim /etc/mariadb/my.cnf

[client]
#password	= your_password
port		= 53307
socket		= /tmp/mariadb53307.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	= 3153307
port		= 53307
socket		= /tmp/mariadb53307.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
……………………


#4. "/usr/local/mysql" 替换为 "/usr/local/mariadb" :%s/\/usr\/local\/mysql/\/usr\/local\/mariadb/g
# 初始化
# 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密码,如设置密码为 "mariadb"
# cd /usr/local/mariadb
# ./bin/mysqladmin -uroot -hlocalhost.localdomain -P53307 password 'mariadb'


# 登录 mariadb 实例
# mysql -uroot -hlocalhost.localdomain -P53307 -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 'mariadb';
alter user root@'127.0.0.1' identified by 'mariadb';
flush privileges;

 

参考: Installing MariaDB Alongside MySQL

  • 1
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值