配置my.cnf

来源:互联网 发布:房地产文案 知乎 编辑:程序博客网 时间:2024/05/19 22:06

默认的my.cnf文件:

[mysqld]
# Settings user and group are ignored when systemd is used.
# If you need to run mysqld under different user or group,
# customize your systemd unit file for mysqld according to the
# instructions in http://fedoraproject.org/wiki/Systemd
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0

[mysqld_safe]
log-error=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid



修改后的my.cnf文件:

[mysqld]
# Settings user and group are ignored when systemd is used.
# If you need to run mysqld under different user or group,
# customize your systemd unit file for mysqld according to the
# instructions in http://fedoraproject.org/wiki/Systemd

# Default directory.
datadir=/var/lib/mysql

# The TCP/IP Port the MySQL Server listens on.
port=3306
bind-address=127.0.0.1

# The Linux Socket the MySQL Server uses when not using a listener.
# socket=/var/lib/mysql/mysql.sock

# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0

# The default storage engine that will be used when createing new tables.
default-storage-engine=INNODB

# Set the SQL mode to strict.
sql-mode="STRICT_TRANS_TABLES,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION"

# Set the maximum number of connections.
max_connections=100

# Set the number of open tables for all threads.
table_cache=256

# Set the maximum size for internal (in-memory) temporary tables.
tmp_table_size=26M

# Set how many threads should be kept in a cache for reuse.
thread_cache_size=8

# MyISAM configuration.
myisam_max_sort_file_size=100G
myisam_sort_buffer_size=52M
key_buffer_size=36M
read_rnd_buffer_size=256K
sort_buffer_size=256K

# InnoDB configuration.
innodb_data_home_dir=/var/lib/mysql
innodb_additional_mem_pool_size=2M
innodb_flush_log_at_trx_commit=1
innodb_log_buffer_size=1M
innodb_buffer_pool_size=25M
innodb_log_file_size=5M
innodb_thread_concurrency=8

[mysqld_safe]
log-error=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid

启动服务后,需要对MySQL Server进行一些安全加固,该脚本位于/usr/bin目录下:

【 ~】$ mysql_secure_installation

这个脚本需要交互性地回应几个提示。第一个提示要求输入root密码,该密码最初是空的。这意味着按回车键即可。下一个问题询问是否要设置root用户的密码。

按Y键和回车键。脚本将提示输入两次root用户的密码。

然后再问是否要删除匿名用户,这是一个必做的项目,按Y键和回车键。下一个问题问是否想不允许root登录。如果这是一个开发机器,那么就应该按Y键和

回车键来限制root登录到本地主机。

然后脚本会问是否想要删除test数据库,是否删除它确实并不重要,但是我建议删除。按Y键和回车键删除测试数据库。最后一个问题问是否要重载权限表,

答案是按Y键和回车键。这将清除现有的安全特权,并重新载入它们,这些重新载入的特权中带有任何在连接MySQL数据库时产生的变化,这一替代需要断开

连接,关闭并重启MySQL实例。

加固数据库后,应该创建一个student用户和studentdb数据库。

0 0