Cài đặt MariaDB cùng với MySQL

MariaDB được rút ra và thay thế cho MySQL, nhưng bạn cũng có thể cài đặt nó cùng với MySQL. (Điều này có thể hữu ích, ví dụ, nếu bạn muốn di chuyển cơ sở dữ liệu/ ứng dụng từng cái một)

Dưới đây là các bước để cài đặt MariaDB bên cạnh một bản cài đặt MySQL sẵn có.

  • Tải về tập tin nhị phân đã được biên dịch định dạng tar.gz chứa phiên bản mới nhất (mariadb-5.5.24-linux-x86_64.tar.gz - như bài viết này) và giải nén tập tin vào một thư mục theo lựa chọn của bạn. Trong bài viết này, tôi sẽ giả định bạn sử dụng thư mục là /opt.
[root@mariadb-near-mysql ~]# cat /etc/issue
CentOS release 6.2 (Final)

[root@mariadb-near-mysql ~]# rpm -qa mysql*
mysql-5.1.61-1.el6_2.1.x86_64
mysql-libs-5.1.61-1.el6_2.1.x86_64
mysql-server-5.1.61-1.el6_2.1.x86_64

[root@mariadb-near-mysql ~]# ps axf | grep mysqld
 2072 pts/0    S+     0:00          \_ grep mysqld
 1867 ?        S      0:01 /bin/sh /usr/bin/mysqld_safe --datadir=/var/lib/mysql --socket=/var/lib/mysql/mysql.sock ...
 1974 ?        Sl     0:06  \_ /usr/libexec/mysqld --basedir=/usr --datadir=/var/lib/mysql --user=mysql ...
  • Tạo thư mục dữ liệu và liên kết tượng trưng như dưới đây:
[root@mariadb-near-mysql opt]# mkdir mariadb-data
[root@mariadb-near-mysql opt]# ln -s mariadb-5.5.24-linux-x86_64 mariadb
[root@mariadb-near-mysql opt]# ls -al
total 20
drwxr-xr-x.  5 root root 4096 2012-06-06 07:27 .
dr-xr-xr-x. 23 root root 4096 2012-06-06 06:38 ..
lrwxrwxrwx.  1 root root   27 2012-06-06 07:27 mariadb -> mariadb-5.5.24-linux-x86_64
drwxr-xr-x. 13 root root 4096 2012-06-06 07:07 mariadb-5.5.24-linux-x86_64
drwxr-xr-x.  2 root root 4096 2012-06-06 07:26 mariadb-data
  • Tạo nhóm người dùng mariadb và người dùng mariadb và đặt đúng quyền sở hữu:
[root@mariadb-near-mysql opt]# groupadd --system mariadb
[root@mariadb-near-mysql opt]# useradd -c "MariaDB Server" -d /opt/mariadb -g mariadb --system mariadb
[root@mariadb-near-mysql opt]# chown -R mariadb:mariadb mariadb-5.5.24-linux-x86_64/
[root@mariadb-near-mysql opt]# chown -R mariadb:mariadb mariadb-data/
  • Tạo một tập tin my.cnf mới trong /opt/mariadb từ các tập tin hỗ trợ:
[root@mariadb-near-mysql opt]# cp mariadb/support-files/my-medium.cnf mariadb-data/my.cnf
[root@mariadb-near-mysql opt]# chown mariadb:mariadb mariadb-data/my.cnf
  • Sửa tập tin /opt/mariadb-data/my.cnf và thêm đường dẫn tùy chỉnh, socket, cổng, người dùng và quan trọng hơn tất cả: thư mục dữ liệu và thư mục cơ sở. Cuối cùng tập tin ít nhất như thế dưới đây:
[client]
port    = 3307
socket    = /opt/mariadb-data/mariadb.sock

[mysqld]
datadir         = /opt/mariadb-data
basedir         = /opt/mariadb
port    = 3307
socket    = /opt/mariadb-data/mariadb.sock
user            = mariadb
  • Sao chép đoạn mã init.d từ tập tin hỗ trợ trong vị trí đúng:
[root@mariadb-near-mysql opt]# cp mariadb/support-files/mysql.server /etc/init.d/mariadb
[root@mariadb-near-mysql opt]# chmod +x /etc/init.d/mariadb
  • Sửa /etc/init.d/mariadb thay thế mysql bởi mariadb như dưới đây:
- # Provides: mysql
+ # Provides: mariadb
- basedir=
+ basedir=/opt/mariadb
- datadir=
+ datadir=/opt/mariadb-data
- lock_file_path="$lockdir/mysql"
+ lock_file_path="$lockdir/mariadb"

Phần khó khăn nhất sẽ là thay đổi cuối cùng trong tập tin này. Bạn cần phải nói với mariadb để sử dụng chỉ một tập tin cnf. TRong phần start sau $bindir/mysqld_safe thêm --defaults-file=/opt/mariadb-data/my.cnf. Cuối cùng các dòng cấu hình nên như thế này:

# Give extra arguments to mysqld with the my.cnf file. This script
# may be overwritten at next upgrade.
$bindir/mysqld_safe --defaults-file=/opt/mariadb-data/my.cnf --datadir="$datadir" --pid-file="$mysqld_pid_file_path" $other_args >/dev/null 2>&1 &
  • Chạy mysql_install_db bằng cách đưa ra tập tin my.cnf một cách rõ ràng như là đối số:
[root@mariadb-near-mysql opt]# cd mariadb
[root@mariadb-near-mysql mariadb]# scripts/mysql_install_db --defaults-file=/opt/mariadb-data/my.cnf
  • Bây giờ bạn có thể bắt đầu MariaDB bằng cách
[root@mariadb-near-mysql opt]# /etc/init.d/mariadb start
Starting MySQL...                                          [  OK  ]
  • Làm cho MariaDB khởi động lúc hệ thống khởi động:
[root@mariadb-near-mysql opt]# cd /etc/init.d
[root@mariadb-near-mysql init.d]# chkconfig --add mariadb 
[root@mariadb-near-mysql init.d]# chkconfig --levels 3 mariadb on
  • Cuối cùng kiểm thử rằng bạn có cả hai cơ sở dữ liệu cùng hoạt động:
[root@mariadb-near-mysql ~]# mysql -e "SELECT VERSION();"
+-----------+
| VERSION() |
+-----------+
| 5.1.61    |
+-----------+
[root@mariadb-near-mysql ~]# mysql -e "SELECT VERSION();" --socket=/opt/mariadb-data/mariadb.sock
+----------------+
| VERSION()      |
+----------------+
| 5.5.24-MariaDB |
+----------------+

Nâng cấp MariaDB thế nào ?

Bởi có tập tin mariadb.socket, my.cnfdatabases trong /opt/mariadb-data nếu bạn muốn nâng cấp phiên bản MariaDB bạn sẽ chỉ cần:

  • giải nén phiên bản mới từ tập tin nén trong /opt gần phiên bản hiện tại
  • dừng MariaDB
  • thay đổi liên kết tượng trưng mariadb để trỉ đến thư mục mới
  • khởi chạy MariaDB
  • chạy đoạn mã thực thi việc nâng cấp... nhưng nhớ rằng bạn cần cung cấp tùy chọn socket --socket=/opt/mariadb-data/mariadb.sock

Bình luận

Đang nạp Bình luận...
Content reproduced on this site is the property of its respective owners, and this content is not reviewed in advance by MariaDB. The views, information and opinions expressed by this content do not necessarily represent those of MariaDB or any other party.