1 Hướng dẫn cài đặt MySQL 5.5.10 trên Fedora 14/13, CentOS/Red Hat (RHEL) 5.5/6 Tue Aug 02, 2011 9:12 am
Đại Ka Forum
Moderator
MySQL là hệ thống quản trị cơ sở dữ liệu họat động như một như một chủ cung cấp truy nhập đa người dùng vào một số cơ sở dữ liệu (CSDL). Đây là chương trình nguồn mở, miễn phí, ổn định và khá an tòan. Bài viết này hướng dẫn việc cài đặt, nâng cấp MySQL Community Server trên Fedora 14 (13, 12, 11, 10, 9, Cool, CentOS 5.5 and Red Hat (RHEL) 5.5/6.
Lưu ý: nếu bạn nâng cấp MySQL thì nên thực hiện sao lưu lại các thiết lập và dữ liệu trước. Thực hiện với lệnh mysql_upgrade.
Cài đặt CSDL MySQL 5.5.10 trên Fedora 13/14, CentOS 5.5, RedHat (RHEL) 5.5/6
1. chuyển sang tài khỏan root
su -
## hoặc ##
sudo -i
2. cài đặt Remi repository
Fedora
CentOS và RedHat (RHEL)
3. kiểm tra phiên bản MySQL sẵn có
Fedora
Fedora 14, (13, 12, 11, 10, 9, Cool
CentOS 5.5 và Red Hat (RHEL) 5.5/6
output:
4. Cập nhật và cài đặt MySQL 5.5.10
Fedora 14 (13,12,11,10,9,8,7)
CentOS 5.5 và RedHat (RHEL) 5.5
5. chạy MySQL và đặt chế độ tự chạy MySQL khi khởi động máy
6. MySQL Secure Installation
thay đổi mật khẩu root
xóa bỏ người dùng vô danh
không cho phép root đăng nhập từ xa
hủy bỏ kiểm tra và truy cập dữ liệu
tải lại các bảng đặc quyền
Khởi động MySQL Secure Installation với dòng lệnh sau:
Output:
lưu ý: nên thay đổi mật khẩu root
7. Kết nối tới cơ sở dữ liệu MySQL(localhost) với mật khẩu
8. Tạo cơ sở dữ liệu, tạo người dùng MySQL và kích họat các kết nối từ xa đến CSDL MySQL
Dưới đây là 1 ví dụ với các thông số:
DB_NAME = webdb
USER_NAME = webdb_user
REMOTE_IP = 10.0.15.25
PASSWORD = password123
PERMISSIONS = ALL
Kích hoạt kết nối từ xa đến máy chủ MySQL-- mở cổng MySQL 3306 trên Iptable Firewall (sử dụng tài khỏan root)
1. Chỉnh sửa tập tin /etc/sysconfig/iptables:
2. thêm dòng sau đây trước COMMIT:
3. Khởi động lại Iptables Firewall:
4. Kiểm tra kết nối từ xa:
Lưu ý: nếu bạn nâng cấp MySQL thì nên thực hiện sao lưu lại các thiết lập và dữ liệu trước. Thực hiện với lệnh mysql_upgrade.
Cài đặt CSDL MySQL 5.5.10 trên Fedora 13/14, CentOS 5.5, RedHat (RHEL) 5.5/6
1. chuyển sang tài khỏan root
su -
## hoặc ##
sudo -i
2. cài đặt Remi repository
Fedora
## Remi Dependency on Fedora 14, 13, 12, 11, 10, 9, 8
rpm -Uvh [You must be registered and logged in to see this link.] rpmfusion.org/free/fedora/rpmfusion-free-release-stable. noarch. rpm
rpm -Uvh [You must be registered and logged in to see this link.] rpmfusion.org/nonfree/fedora/rpmfusion-nonfree-release-stable. noarch. rpm
## Fedora 14 ##
rpm -Uvh [You must be registered and logged in to see this link.] famillecollet.com/remi-release-14. rpm
## Fedora 13 ##
rpm -Uvh [You must be registered and logged in to see this link.] famillecollet.com/remi-release-13. rpm
## Fedora 12 ##
rpm -Uvh [You must be registered and logged in to see this link.] famillecollet.com/remi-release-12. rpm
## Fedora 11 ##
rpm -Uvh [You must be registered and logged in to see this link.] famillecollet.com/remi-release-11. rpm
## Fedora 10 ##
rpm -Uvh [You must be registered and logged in to see this link.] famillecollet.com/remi-release-10. rpm
## Fedora 9 ##
rpm -Uvh [You must be registered and logged in to see this link.] famillecollet.com/remi-release-9. rpm
## Fedora 8 ##
rpm -Uvh [You must be registered and logged in to see this link.] famillecollet.com/remi-release-8. rpm
CentOS và RedHat (RHEL)
- Code:
## Remi Dependency on CentOS and Red Hat (RHEL)
rpm -Uvh http://download. fedora. redhat.com/pub/epel/5/i386/epel-release-5-4. noarch. rpm
Red Hat (RHEL) 6
rpm -Uvh http://rpms. famillecollet.com/enterprise/remi-release-6. rpm
## CentOS 5.5 and Red Hat (RHEL) 5.5
rpm -Uvh http://rpms. famillecollet.com/enterprise/remi-release-5. rpm
3. kiểm tra phiên bản MySQL sẵn có
Fedora
yum list mysql
Fedora 14, (13, 12, 11, 10, 9, Cool
yum --enablerepo=remi list mysql mysql-server
CentOS 5.5 và Red Hat (RHEL) 5.5/6
yum --enablerepo=remi, remi-test list mysql mysql-server
output:
- Code:
d plugins: changelog, fastestmirror, presto, refresh-packagekit
...
remi | 3.0 kB 00:00
remi/primary_db | 106 kB 00:00
Available Packages
mysql. i686 5.5.10-1. fc14. remi @remi
mysql-server. i686 5.5.10-1. fc14. remi @remi
4. Cập nhật và cài đặt MySQL 5.5.10
Fedora 14 (13,12,11,10,9,8,7)
yum --enablerepo=remi install mysql mysql-server
CentOS 5.5 và RedHat (RHEL) 5.5
yum --enablerepo=remi, remi-test install mysql mysql-server
5. chạy MySQL và đặt chế độ tự chạy MySQL khi khởi động máy
/etc/init. d/mysqld start ## dùng khởi động lại sau khi cập nhật
## hoặc ##
service mysqld start ## dùng khởi động lại sau khi cập nhật
chkconfig --levels 235 mysqld on
6. MySQL Secure Installation
thay đổi mật khẩu root
xóa bỏ người dùng vô danh
không cho phép root đăng nhập từ xa
hủy bỏ kiểm tra và truy cập dữ liệu
tải lại các bảng đặc quyền
Khởi động MySQL Secure Installation với dòng lệnh sau:
/usr/bin/mysql_secure_installation
Output:
NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MySQL
SERVERS IN PRODUCTION USE! PLEASE READ EACH STEP CAREFULLY!
In order to log into MySQL to secure it, we\'ll need the current
password for the root user. If you\'ve just installed MySQL, 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):
OK, successfully used password, moving on...
Setting the root password ensures that nobody can log into the MySQL
root user without the proper authorisation.
Set root password? [Y/n] Y
New password:
Re-enter new password:
Password updated successfully!
Reloading privilege tables. .
... Success!
Bi default, a MySQL installation has an anonymous user, allowing anyone
to log into MySQL 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.
Remove anonymous users? [Y/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.
Disallow root login remotely? [Y/n] Y
... Success!
Bi default, MySQL 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.
Remove test database and access to it? [Y/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.
Reload privilege tables now? [Y/n] Y
... Success!
Cleaning up...
All done! If you\'ve completed all of the above steps, your MySQL
installation should now be secure.
Thanks for using MySQL!
lưu ý: nên thay đổi mật khẩu root
mysqladmin -u root password [your_password_here]
## Example ##
mysqladmin -u root password myownsecrectpass
7. Kết nối tới cơ sở dữ liệu MySQL(localhost) với mật khẩu
mysql -u root -p
## OR ##
mysql -h localhost -u root -p
8. Tạo cơ sở dữ liệu, tạo người dùng MySQL và kích họat các kết nối từ xa đến CSDL MySQL
Dưới đây là 1 ví dụ với các thông số:
DB_NAME = webdb
USER_NAME = webdb_user
REMOTE_IP = 10.0.15.25
PASSWORD = password123
PERMISSIONS = ALL
## tạo CSDL ##
mysql> CREATE DATABASE webdb;
## tạo người dùng ##
mysql> CREATE USER 'webdb_user'@'10.0.15.25' IDENTIFIED Bi 'password123';
## cấp quyền GRANT##
mysql> GRANT ALL ON webdb. * TO webdb_user@'10.0.15.25';
## FLUSH PRIVILEGES, Tell the server TO reload the GRANT TABLES ##
mysql> FLUSH PRIVILEGES;
Kích hoạt kết nối từ xa đến máy chủ MySQL-- mở cổng MySQL 3306 trên Iptable Firewall (sử dụng tài khỏan root)
1. Chỉnh sửa tập tin /etc/sysconfig/iptables:
nano -w /etc/sysconfig/iptables
2. thêm dòng sau đây trước COMMIT:
-A RH-Firewall-1-INPUT -m state --state NEW -m tcp -p tcp --dport 3306 -j ACCEPT
3. Khởi động lại Iptables Firewall:
service iptables restart
## OR ##
/etc/init. d/iptables restart
4. Kiểm tra kết nối từ xa:
mysql -h dbserver_name_or_ip_address -u webdb_user -p webdb