centos7下载安装mysql5.7.22(手动配置-容易崩)

原文连接:https://blog.csdn.net/vipbupafeng/article/details/80271089

官网链接:https://dev.mysql.com/downloads/mysql/5.7.html#downloads
在这里插入图片描述
或在线下载
wget https://cdn.mysql.com//Downloads/MySQL-5.7/mysql-5.7.22-linux-glibc2.12-x86_64.tar.gz
wget https://cdn.mysql.com//Downloads/MySQL-5.7/mysql-5.7.23-linux-glibc2.12-x86_64.tar.gz
在这里插入图片描述
由于这里所使用的是纯净版centos,所以要先设立mysql文件夹
在这里插入图片描述
tar zxvf mysql-5.7.22-linux-glibc2.12-x86_64.tar.gz -C /usr/local/mysql

建议:不要安装到其它目录,否则数据库初始化的时候会报cannot change dir的错,不好搞
在这里插入图片描述
重命名
mv mysql-5.7.22-linux-glibc2.12-x86_64 mysql
在这里插入图片描述
创建用户组和用户

创建用户组:groupadd mysql

创建用户:useradd -r -g mysql mysql

为了安全性,给mysql数据库创建专有用户,该用户只能访问mysql目录,不能访问系统其它目录

另外不建议直接用root初始化mysql,否则连接mysql时会报错:[ERROR] Fatal error: Ple read “Security” section of the manual to find out how to run mysqld root!

给mysql目录指定专有用户组和目录

首先创建data目录:

cd /usr/local/mysql

mkdir data

指定用户和用户组:

cd /usr/local

chown -R mysql mysql/

chgrp -R mysql mysql/

-R包含目录下所有和目录和文件

初始化mysql
cd /usr/local/mysql/bin

./mysqld --initialize --user=mysql --edir=/usr/local/mysql/ --datadir=/usr/local/mysql/data/ --lc_messages_dir=/usr/local/mysql/share --lc_messages=en_US

记住生成的临时密码
如果忘记密码或者想重新初始化,可以先将mysql/data目录中文件删除,然后再执行初始化命令
在这里插入图片描述
配置my.cnf文件
cd /etc
cat>>my.cnf
输入以下内容,ctrl+D退出

# For advice on how to change settings ple 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
# 一般配置选项
edir = /usr/local/mysql/
datadir = /usr/local/mysql/data
port = 3306
character-set-server = utf8
explicit_defaults_for_timestamp = true
# socket = /var/run/mysqld/mysqld.sock
#下面是可选项,要不要都行,如果出现启动错误,则全部注释掉,保留最基本的配置选项,然后尝试添加某些配置项后启动,检测配置项是否有误
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-reh
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]
# /bin/h: Q: command not found

启动
cd /usr/local/mysql/bin

启动:./mysqld_safe --user=mysql &
在这里插入图片描述
设为开机启动
cd /usr/local/mysql/support-files/
cp mysql.server /etc/init.d/mysql
vi /etc/init.d/mysql

将mysql目录填上:
edir=/usr/local/mysql/
datadir=/usr/local/mysql/data/
在这里插入图片描述
授权:chmod +x /etc/init.d/mysql
设为开机启动:chkconfig --add mysql

启动服务
重启服务:service mysql restart
在这里插入图片描述
停止服务:service mysql stop
启动服务:service mysql start
查看服务:service mysql status

修改mysql密码以及允许远程连接
cd /usr/local/mysql/bin
登录:./mysql -u root -p 输入临时密码
在这里插入图片描述
修改密码:set sword=sword(“root”);
在这里插入图片描述
登录授权:grant all privileges on . to’root’ @’%’ identified by ‘root’;

授权生效:flush privileges;
在这里插入图片描述
可使用navicat或sqlyog等工具进行登录,注意关闭防火墙或开放3306端口

开放端口-防火墙

查看活动的连接

firewall-cmd --get-active-zones

添加端口到防火墙中

firewall-cmd --zone=public --add-port=3306/tcp --permanent

防火墙重新读取端口列表

firewall-cmd --reload
在这里插入图片描述
mysql 启动错误解决方法

错误代码:Starting MySQL. ERROR! The server quit without updating PID file (/usr/local/mysql/mysql/data/localhost.localdomain.pid).

1.先跳转到错误代码处 cd /usr/local/mysql/mysql/data

  • 0
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值