Linux下安装mysql5.7缺少my-default.cnf文件及Can't connect to local MySQL server 解决方案
2017-07-23 17:21
417 查看
在Linux下面安装mysql5.7版本,配置/etc/my.cnf文件,按照安装步骤到mysql/support-files目录下,发现缺少这个my_default.cnf默认的配置文件,如果没有默认的配置文件,需要在该目录下面手动创建一个my_default.cnf配置文件。
下面是网上通用的自定义my_default.cnf文件内容:
# For advice on how to change settings please see
# http://dev.mysql.com/doc/refman/5.7/en/server-configuration-defaults.html
# *** DO NOT EDIT THIS FILE. It's a template which will be copied to the
# *** default location during install, and will be replaced if you
# *** upgrade to a newer version of MySQL.
[mysqld]
sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES
# 一般配置选项
basedir = /usr/local/mysql
datadir = /usr/local/mysql/data
port = 3306
socket = /usr/local/mysql/mysqld/mysql.sock
character-set-server=utf8
#下面是可选项,要不要都行,如果出现启动错误,则全部注释掉,保留最基本的配置选项,然后尝试添加某些配置项后启动,检测配置项是否有误
back_log = 300
max_connections = 3000
max_connect_errors = 50
table_open_cache = 4096
max_allowed_packet = 32M
#binlog_cache_size = 4M
max_heap_table_size = 128M
read_rnd_buffer_size = 16M
sort_buffer_size = 16M
join_buffer_size = 16M
thread_cache_size = 16
query_cache_size = 128M
query_cache_limit = 4M
ft_min_word_len = 8
thread_stack = 512K
transaction_isolation = REPEATABLE-READ
tmp_table_size = 128M
#log-bin=mysql-bin
long_query_time = 6
server_id=1
innodb_buffer_pool_size = 1G
innodb_thread_concurrency = 16
innodb_log_buffer_size = 16M
innodb_log_file_size = 512M
innodb_log_files_in_group = 3
innodb_max_dirty_pages_pct = 90
innodb_lock_wait_timeout = 120
innodb_file_per_table = on
[mysqldump]
quick
max_allowed_packet = 32M
[mysql]
no-auto-rehash
default-character-set=utf8
safe-updates
[myisamchk]
key_buffer = 16M
sort_buffer_size = 16M
read_buffer = 8M
write_buffer = 8M
[mysqlhotcopy]
interactive-timeout
[mysqld_safe]
log-error=/usr/local/mysql/log/mysqld.log
pid-file=/usr/local/mysql/mysqld/mysqld.pid
open-files-limit = 8192
配置完毕,记得 cp my_default.cnf /etc/my.cnf
如果按照标准配置了mysql服务就可以 执行 service mysqld start 或者 /etc/init.d/mysqld start
服务正常启动之后可以通过 ps -ef|grp mysql 查询进程是否存在
连接myql服务 mysql -u root -p
注意:如果报错 Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2)
可以尝试在 /etc/my.cnf 文件中添加如下内容:
[client]
socket=/usr/local/mysql/mysqld/mysql.sock
[mysqld]
socket=/usr/local/mysql/mysqld/mysql.sock
另外,在安装的过程中新建的mysql相关的文件及文件夹,注意用户、用户组、权限范围,拒绝入坑!
下面是网上通用的自定义my_default.cnf文件内容:
# For advice on how to change settings please see
# http://dev.mysql.com/doc/refman/5.7/en/server-configuration-defaults.html
# *** DO NOT EDIT THIS FILE. It's a template which will be copied to the
# *** default location during install, and will be replaced if you
# *** upgrade to a newer version of MySQL.
[mysqld]
sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES
# 一般配置选项
basedir = /usr/local/mysql
datadir = /usr/local/mysql/data
port = 3306
socket = /usr/local/mysql/mysqld/mysql.sock
character-set-server=utf8
#下面是可选项,要不要都行,如果出现启动错误,则全部注释掉,保留最基本的配置选项,然后尝试添加某些配置项后启动,检测配置项是否有误
back_log = 300
max_connections = 3000
max_connect_errors = 50
table_open_cache = 4096
max_allowed_packet = 32M
#binlog_cache_size = 4M
max_heap_table_size = 128M
read_rnd_buffer_size = 16M
sort_buffer_size = 16M
join_buffer_size = 16M
thread_cache_size = 16
query_cache_size = 128M
query_cache_limit = 4M
ft_min_word_len = 8
thread_stack = 512K
transaction_isolation = REPEATABLE-READ
tmp_table_size = 128M
#log-bin=mysql-bin
long_query_time = 6
server_id=1
innodb_buffer_pool_size = 1G
innodb_thread_concurrency = 16
innodb_log_buffer_size = 16M
innodb_log_file_size = 512M
innodb_log_files_in_group = 3
innodb_max_dirty_pages_pct = 90
innodb_lock_wait_timeout = 120
innodb_file_per_table = on
[mysqldump]
quick
max_allowed_packet = 32M
[mysql]
no-auto-rehash
default-character-set=utf8
safe-updates
[myisamchk]
key_buffer = 16M
sort_buffer_size = 16M
read_buffer = 8M
write_buffer = 8M
[mysqlhotcopy]
interactive-timeout
[mysqld_safe]
log-error=/usr/local/mysql/log/mysqld.log
pid-file=/usr/local/mysql/mysqld/mysqld.pid
open-files-limit = 8192
配置完毕,记得 cp my_default.cnf /etc/my.cnf
如果按照标准配置了mysql服务就可以 执行 service mysqld start 或者 /etc/init.d/mysqld start
服务正常启动之后可以通过 ps -ef|grp mysql 查询进程是否存在
连接myql服务 mysql -u root -p
注意:如果报错 Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2)
可以尝试在 /etc/my.cnf 文件中添加如下内容:
[client]
socket=/usr/local/mysql/mysqld/mysql.sock
[mysqld]
socket=/usr/local/mysql/mysqld/mysql.sock
另外,在安装的过程中新建的mysql相关的文件及文件夹,注意用户、用户组、权限范围,拒绝入坑!
相关文章推荐
- CentOS下安装mysql和解决ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/run/my
- 启动SQL提示"Can't connect to local MySQL server through socket '/tmp/mysql.sock"参考解决方案
- Linux下Mysql数据库 Can 't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock '
- Error 2002 (HY000): Can't connect to local MySOL server through socket '/var/lib/mysql.sock' (2 "No
- centos7 安装mysql 报错:亲测有效,解决Can 't connect to local MySQL server through socket '/tmp/mysql.sock '(2)
- CentOS yum安装mysql后 Can’t connect to local MySQL server through socket ‘/var/lib/mysql/mysql.sock’
- 新安装的MySQL的root用户没有密码,但是出现ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/va
- zabbix到安装界面报错" Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock"
- linux下启动、登陆 mysql 出现ERROR 2002(HY000):can't connect to local mysql server
- 安装mysql后ERROR 2002 (HY000): Can’t connect to local MySQL server through socket ‘/var mysql 启动不了
- Linux上mysql登陆错误解决办法ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/lib/
- CentOS yum安装mysql后 Can’t connect to local MySQL server through socket ‘/var/lib/mysql/mysql.sock’
- CentOS yum安装mysql后 Can’t connect to local MySQL server through socket ‘/var/lib/mysql/mysql.sock’
- 关于ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/lib的解决方案之一
- ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2) 报错解决方案
- Ubuntu14.04 安装MySQL 及Can‘t connect to local MYSQL server through socket ’/var/run/mysqld/mysqld.sock‘ (2)
- mysql安装出现can't connect to local mysql server through socket /tmp/mysql.sock
- linux系统上启动mysql报错2002:ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/l
- mysql搭建安装常见问题:ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/lib/mysql
- Linux下MySql出现Can’t connect to local MySQL server through socket