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依赖库
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
__EOF__
关于博主:擅长性能、全链路、自动化、企业级自动化持续集成(DevTestOps)、测开等
面试必备:项目实战(性能、自动化)、简历笔试,https://www.cnblogs.com/uncleyong/p/15777706.html
测试提升:从测试小白到高级测试修炼之路,https://www.cnblogs.com/uncleyong/p/10530261.html
欢迎分享:如果您觉得文章对您有帮助,欢迎转载、分享,也可以点击文章右下角【推荐】一下!