系统centos 7.0

yum install -y mariadb mariadb-server python2-PyMySQL

设置最大连接数

vim /etc/security/limits.conf
> *       soft    nofile  65535
> *       hard    nofile  65535
> *       soft    noproc  65535
> *       hard    noproc  65535

#生效
sysctl -p
#未失效则重启系统
rebbot
#查看
ulimit -n

配置

vim /etc/my.cnf

[client-server]
 #mysqld     = /usr/local/mysql/bin/mysqld_safe
 #mysqladmin = /usr/local/mysql/bin/mysqladmin
 user       = mysql
 port        = 3306
 socket        = /var/run/mysql.sock
 
 # The MySQL server
 [mysqld]
 symbolic-links=0
 port        = 3306
 bind-address    = 192.168.100.76
 socket        = /var/run/mysql.sock
 
 datadir     = /data/dbdata
 pid-file    = /var/run/my.pid
 skip-external-locking
 skip-name-resolve
 interactive_timeout=86400
 wait_timeout=86400
 key_buffer_size = 384M
 max_allowed_packet = 4M
 
 table_open_cache = 81920
 sort_buffer_size = 2M
 read_buffer_size = 2M
 myisam_sort_buffer_size = 64M
 query_cache_size = 640M
 # 线程缓存
 thread_cache_size = 320

# 连接数限制
 max_connection = 4096
 max_connect_errors=4000
 max_heap_table_size = 640M
 open_files_limit=20480
 # 日志
 slow_query_log = 1
 long_query_time = 5
 slow-query-log-file = /data/logs/slowquery.log
 log-bin        = /data/logs/binlog
 # 字符集
 character-set-server = utf8
 collation_server = utf8_general_ci
 # 如果您使用主从结构,请取消注释以下内容,并进行修改
 # server-id    = 100
 # master-host            =    192.168.0.100
 # master-user            =    repuser
 # master-password        =    repuser123
 # master-port            =    6033
 # master-connect-retry   =    30
 # log-slave-updates
 # skip-slave-start
 # master-info-file = /data/dbdata/master.info
 
 # 如果您使用InnoDB表,请取消注释以下内容
 # innodb_data_home_dir = /data/innodb
 # innodb_data_file_path = ibdata1:200M;ibdata2:200M;ibdata3:200M;ibdata4:200M;ibdata5:200M
 # innodb_log_group_home_dir = /data/innodb/
 # innodb_log_arch_dir = /data/innodb/
 # innodb_buffer_pool_size = 700M 
 # innodb_additional_mem_pool_size = 256M 
 # innodb_log_file_size = 256M 
 # innodb_log_buffer_size = 32M 
 # innodb_flush_log_at_trx_commit = 0
 # innodb_lock_wait_timeout = 50
 
 default_storage_engine = innodb
 innodb_file_per_table

chmod a+w /run mkdir -pv /data/{dbdata,logs} chown -R mysql.mysql /data

启动

systemctl restart mariadb systemctl enable mariadb

mysql安装设置

ln -s /var/run/mysql.sock /var/lib/mysql/mysql.sock

mysql_secure_installation

会设置root用户密码,删除匿名用户,禁止root用户远程登录,删除测试库,刷新权限

报错

[Warning] Could not increase number of max_open_files to more than 1024 (request: 8203)

设置系统连接数 检查目录权限 所有配置写在my.cnf中

查看数据库中提供的存储引擎

show engines; 看你的mysql当前默认的存储引擎: show variables like '%storage_engine%';