Cài đặt MariaDB phiên bản 5.5

MariaDB là một sản phẩm mã đóng tách ra từ mã mở do cộng đồng phát triển của hệ quản trị cơ sở dữ liệu quan hệ MySQL nhằm theo hướng không phải trả phí với GNU GPL. MariaDB được định hướng để duy trì khả năng tương thích cao với MySQL, để đảm bảo khả năng hỗ trợ về thư viện đồng thời kết hợp một cách tốt nhất với các API và câu lệnh của MySQL. MariaDB đã có công cụ hỗ lưu trữ XtraDB thay cho InnoDB, cũng như một công cụ lưu trữ mới, Aria. Mariadb thường dùng kết hợp với Webserver, PHP để tạo thành LEMP stack hoặc LAMP stack.

Dưới đây tôi sẽ hướng dẫn các bạn cách cài đặt MariaDB phiên bản 5.5.

Phần 1: Cài đặt MariaDB 5.5

  • Ta sử dụng câu lệnh để tiến hành cài đặt:
[root@localhost ~] #  -y install mariadb-server
  • Sử dụng câu lệnh sau để vào thư mục và tiến hành thay đổi:
[root@localhost ~] # vi /etc/my.cnf

# Thêm dòng dưới đây sau phần [mysqld]

[mysqld]
character-set-server=utf8
  • Lưu lại thay đổi và thoát ra bằng lệnh “:wq
  • Ta dùng câu lệnh để bắt đầu và kích hoạt MariaDB:
[root@localhost ~]# systemctl start mariadb 

[root@localhost ~]# systemctl enable mariadb 

Phần 2: Cài đặt ban đầu cho MariaDB

[root@localhost ~]# mysql_secure_installation 

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): # Nhấn Enter
OK, successfully used password, moving on...

Setting the root password ensures that nobody can log into the MariaDB
root user without the proper authorisation.

# Đặt mật khẩu

Set root password? [Y/n] # Nhấn chọn y
New password: # Điền password mới
Re-enter new password: # Nhập lại password mới
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.

# Xóa người dùng ẩn danh

Remove anonymous users? [Y/n] # Nhấn chọ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.

# Không cho phép đăng nhập root từ xa

Disallow root login remotely? [Y/n] # Nhấn chọn y
 ... Success!

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.

# Xóa cơ sở dữ liệu

Remove test database and access to it? [Y/n] # Nhấn chọn y
 - 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.

# Tải lại các bảng đặc quyền

Reload privilege tables now? [Y/n] # Nhấn chọ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!
  • Kết nối với MariaDB bằng root
[root@localhost ~]# mysql -u root -p 

Enter password: # Nhập password mà bạn đã đặt
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 3
Server version: 5.5.37-MariaDB MariaDB Server

Copyright (c) 2000, 2014, Oracle, Monty Program Ab and others.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

# Hiển thị danh sách người dùng

MariaDB [(none)]> select user,host,password from mysql.user; 
+------+-----------+-------------------------------------------+
| user | host      | password                                  |
+------+-----------+-------------------------------------------+
| root | localhost | *xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx |
| root | 127.0.0.1 | *xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx |
| root | ::1       | *xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx |
+------+-----------+-------------------------------------------+
3 rows in set (0.00 sec)

# Hiển thị danh sách cơ sở dữ liệu

MariaDB [(none)]> show databases; 
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| performance_schema |
+--------------------+
3 rows in set (0.00 sec)

MariaDB [(none)]> exit

Bye
  • Nếu Firewalld đang chạy và MariaDB cũng được sử dụng từ các Máy chủ từ xa, bạn hãy cho phép dịch vụ MariaDB sử dụng 3306 / TCP.
[root@localhost ~]# firewall-cmd --add-service=mysql --permanent 
success
[root@localhost ~]# firewall-cmd --reload 
success

Vậy là đã xong

Xem tiếp:   Hướng dẫn cài Mysql 5.6 trên Ubuntu 20.04

Chúc các bạn thành công!

xem thêm:

Hướng dẫn cài đặt WordPress trên Centos 7

hướng dẫn cấu hình httpd trên centos

Related Posts

Check Also

login_mysql

Hướng dẫn cài Mysql 5.6 trên Ubuntu 20.04

Nếu đang sử dụng Ubuntu 20.x mà cần  cài mysql 5.6 để sử dụng thì …