遇一山,过一山,处处有风景;只要勇敢向前,一路尽是繁花盛开。 | (点击查看→)【测试干货】python/java自动化、持续集成、性能、测开、简历、笔试面试等

mysql5.7二进制安装(centos7)

本文演示centos7下二进制安装mysql。

下载

建议百度网盘下载,或者:https://www.cnblogs.com/uncleyong/p/13785675.html

 

解压

tar -zxvf mysql-5.7.26-linux-glibc2.12-x86_64.tar.gz

 

移动并改名

移动到/usr/local下,并改名为mysql:mv mysql-5.7.26-linux-glibc2.12-x86_64 /usr/local/mysql

 

配置环境变量

vim /etc/profile

# mysql5.7
export PATH=/usr/local/mysql/bin:$PATH

 

使配置生效:source /etc/profile

 

验证

mysql --version

 

安装libaio依赖库

https://dev.mysql.com/doc/

 

yum list installed libaio

如果没有,就安装:yum -y install libaio

 

创建目录

mkdir -p /mysql/{data,redo,binlog,tmp,logs}

 

配置文件

vim /mysql/my.cnf

[client]
default-character-set = utf8
port = 3306
socket = /mysql/tmp/mysql.sock
 
[mysqld]
port = 3306
character_set_server = utf8
server-id = 1
socket= /mysql/tmp/mysql.sock
basedir = /usr/local/mysql
datadir = /mysql/data
tmpdir = /mysql/tmp
log-error = /mysql/logs/alert.log
pid-file = /mysql/tmp/mysql.pid
log-bin = /mysql/binlog/mysql-bin
slow_query_log_file = /mysql/logs/slow.log
default-storage-engine = INNODB
innodb_data_file_path = ibdatal:2G:autoextend
innodb_log_group_home_dir = /mysql/redo
innodb_file_per_table = 1

 

初始化

mysqld --defaults-file=/mysql/my.cnf --initialize

获取临时密码:grep 'temporary password' /mysql/logs/alert.log

U-K%MUngZ3m=

 

启动服务

nohup mysqld_safe --defaults-file=/mysql/my.cnf --user=root &

 

补充:停止服务命令是mysqladmin -uroot -p"123456" shutdown -S /mysql/tmp/mysql.sock

 

登录

mysql -uroot -p"临时密码"

mysql -uroot -p"U-K%MUngZ3m="

Can't connect to local MySQL server through socket '/tmp/mysql.sock'

解决方案:

  • 方案一:指定sock文件:-S /mysql/tmp/mysql.sock
  • 方案二:创建软连接,ln -s /mysql/tmp/mysql.sock /tmp

 

mysql -uroot -p"U-K%MUngZ3m=" -S /mysql/tmp/mysql.sock

 

修改密码

set password='123456';

flush privileges;

exit

 

设置远程访问

用新密码重新登录

 

grant all privileges on *.* to root@'%' identified by '123456' with grant option;

 

flush privileges;

 

创建系统服务

vim /usr/lib/systemd/system/mysqld.service

[Unit]
Description=MySQL Server
Documentation=man:mysqld(8)
Documentation=http://dev.mysql.com/doc/refman/en/using-systemd.html
After=network.target
After=syslog.target

[Install]
WantedBy=multi-user.target

[Service]
User=root
Group=root
ExecStart=/usr/local/mysql/bin/mysqld --defaults-file=/mysql/my.cnf --user=root
LimitNOFILE = 5000 

 

设置开机启动并启动服务:systemctl enable --now mysqld

 

是否开机启动:systemctl is-enabled mysqld

 

查看服务状态:systemctl status mysqld

 

启动服务:systemctl start mysqld

 

停止服务:systemctl stop mysqld

 

 
posted @ 2024-02-14 21:47  全栈测试笔记  阅读(433)  评论(0编辑  收藏  举报
浏览器标题切换
浏览器标题切换end