第一次在自己虚机上安装mysql 中间碰到很多问题 在这里记下来,分享一下。
linux centOS 6
mysql版本 mysql-5.7.19-linux-glibc2.12-x86_64.tar.gz
1、groupadd mysql ## 添加一个mysql组
2、useradd -r -g mysql mysql ## 添加一个用户
3、解压缩下载的包,tar -xzvf /usr/local/mysql-5.7.13-linux-glibc2.5-x86_64.tar.gz
4、mv /usr/local/mysql-5.7.13-linux-glibc2.5-x86_64 /usr/local/mysql ##重命名
解压后目录:
5、mkdir /usr/local/mysql/data ## 默认是没有这个文件夹得 用来放数据
6、chown -R mysql:mysql ./ ##进入mysql包中, 给这个包授权 给mysql
7、chgrp -R mysql:mysql ./ ##进入mysql包中
8、bin/mysqld --initialize --user=mysql --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data ##进入mysql文件名 basedir 为mysql 的路径, datadir 为mysql的 data 包,里面 存放着mysql自己的包, 如user
网上很多教程mysql_install_db 方式安装的,我刚开始也是这么安装,各种报错、失败,mysql_install_db 命令不推荐、按上面的命令来就好
此处需要注意记录生成的临时密码,如上文:YLi>7ecpe;YP
9、bin/mysql_ssl_rsa_setup --datadir=/usr/local/mysql/data
10、进入mysql support-files
11、cp my-default.cnf /etc/my.cnf
发现这个版本就没有my-default
这个是时候我们自己创建一个(内部代码如图): 重点下面两个socket(红色)对应的值必须一致,不然启动以后链接不上
#dvice 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 = /temp/mysqld.sock
socket = /var/run/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
socket = /var/run/mysqld/mysqld.sock
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]
loose-default-character-set = utf8
12、cp mysql.server /etc/init.d/mysql
13、vim /etc/init.d/mysql ##修改basedir= 自己的路径 修改datadir= 自己的路径
14、bin/mysqld_safe --user=mysql & ## 启动mysql
13、./mysql -uroot -p ##bin目录下
14、 输入临时密码
15、修改MySQL的root密码
此时mysql只有本地localhost可以访问
16 修改可远程访问
重启MySQL服务
此时本地可以正常使用MySQL
测试远程连接
有的系统无法生成:/var/run/mysqld 汇报 如下错误:
mysqld_safe Directory '/var/run/mysqld' for UNIX socket file don't exists
The server quit without updating PID file (/usr/local/mysql/data/mysql.pid)
解决办法 :
mkdir /var/run/mysqld
chown -R mysql:mysql /var/run/mysqld
chmod 755 /var/run/mysqld
再启动mysql就可以了