如何Redhat Enterprise Linux(RHEL)安装和配置MySQL数据库服务器

如何在Redhat Enterprise Linux 4/5/6下安装MySQL数据库服务器?

红帽企业Linux安装Mysql数据库服务器

执行以下命令,使用RHN或CentOS存储库安装mysql服务器:

在Redhat Enterprise Linux RHEL 5/6 安装MySQL

以root用户身份执行以下命令:

# yum install mysql-server mysql

在Redhat Enterprise Linux RHEL 4/3 安装MySQL

以root用户身份执行以下命令:

# up2date mysql-server mysql

启动MySQL服务

要启动mysql服务器,输入以下命令:

# chkconfig mysqld on
# /etc/init.d/mysqld start

设置mysql root密码

执行以下命令为root用户设置密码:

# mysqladmin -u root password NEWPASSWORD

测试mysql连接

执行以下命令以连接到MySQL服务器:

$ mysql -u root -p

配置mysql服务器

编辑/etc/my.cnf

# vi /etc/my.cnf

配置mysql查询缓存以加快mysql的速度(在[mysqld]中添加):

query_cache_type               = 1
query_cache_limit              = 1M
query_cache_size               = 32M

设置MyISAM缓冲区大小并设置恢复选项:

# For MyISAM #
key_buffer_size                = 24M
myisam_recover                 = FORCE,BACKUP

记录慢速查询用于故障排除:

# LOGGING #
log_queries_not_using_indexes  = 1
slow_query_log                 = 1
slow_query_log_file            = /var/lib/mysql/mysqld-slow-query.log

设置缓存和其他限制如下:

tmp_table_size                 = 32M
max_heap_table_size            = 32M
max_connections                = 500
thread_cache_size              = 50
open_files_limit               = 65535
table_definition_cache         = 4096
table_open_cache               = 512

重新加载或重启,使设置生效:

# /sbin/service mysqld restart

或者

# /sbin/service mysqld reload
日期:2020-03-23 08:03:57 来源:oir作者:oir