linux centos7虚拟机安装mysql过程中的一些坑及解决办法

安装过程主要参考了https://www.cnblogs.com/mujingyu/p/7689116.html的文章,但是过程中也遇到了一些新的问题,总结如下:

1、原始安装包mysql-5.7.26-linux-glibc2.12-x86_64.tar.gz解压之后,在support-files中并不包含my-default.cnf文件,需要自己创建。

我创建的文件内容如下:

my.cnf文件内容

[mysqld]
sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES
# 一般配置选项
default-storage-engine=INNODB
basedir = /usr/local/mysql
datadir = /usr/local/mysql/data
pid-file = /usr/local/mysql/data/mysql.pid
tmpdir = /tmp
port = 3306
socket = /var/lib/mysqld/mysqld.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]
open-files-limit = 8192
[client]
socket = /var/lib/mysqld/mysqld.sock

2、初始化mysql过程中,增加选项,如下:bin/mysqld --initialize --user=mysql --basedir=/usr/local/mysql/ --datadir=/usr/local/mysql/data/ --pid-file=/usr/local/mysql/data/mysql.pid --tmpdir=/tmp

3、修改bin/下面的mysqld_safe文件:

if [ ! -d $mysql_unix_port_dir ]
then
  #log_error "Directory '$mysql_unix_port_dir' for UNIX socket file don't exists."
  #exit 1
  mkdir $mysql_unix_port_dir
  chown $user $mysql_unix_port_dir
  chmod 755 $mysql_unix_port_dir
fi

这可以防止后续mysql服务启动过程中报错:mysqld_safe Directory '/var/lib/mysqld' for UNIX socket file don't exists.

4、如果遇到其他问题,需要重新初始化mysqld并重新启动mysql服务,重启前需要ps -ef| grep mysql并使用kill -9 杀死相关进程,否则,重启失败,并报错:The server quit without updating PID file (/usr/local/mysql/data/mysql.pid)

5、启动后,登录不上mysql,并报错:ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2)

检查my.cnf文件中,client端配置中是否加入了socket = /var/lib/mysqld/mysqld.sock,即[client] \n socket = /var/lib/mysqld/mysqld.sock

或者登录过程中加上-h127.0.0.1参数试试。

猜你喜欢

转载自blog.csdn.net/donyzh/article/details/89883555