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

要进行MySQL 5.7的二进制安装,可以按照以下步骤进行操作: 1. 首先,将MySQL的二进制包解压到/usr/local目录下。你可以使用以下命令: ``` tar xf mysql-5.7.22-linux-glibc2.12-x86_64.tar.gz -C /usr/local/ ``` 2. 接下来,配置启动文件并启动MySQL。你可以使用以下命令: ``` cp support-files/mysql.server /etc/init.d/mysqld chkconfig --add mysqld chkconfig mysqld on service mysqld start ``` 3. 然后,需要初始化MySQL。根据你的操作系统不同,可以使用不同的命令进行安装。如果是CentOS系统,使用以下命令: ``` cd /usr/local/mysql yum -y install libaio* ./bin/mysqld --initialize --user=mysql --basedir=/usr/local/mysql --datadir=/app/mydata/data --innodb_undo_tablespaces=3 --explicit_defaults_for_timestamp ``` 如果是Ubuntu系统,使用以下命令: ``` cd /usr/local/mysql apt-get -y install libaio-dev ./bin/mysqld --initialize --user=mysql --basedir=/usr/local/mysql --datadir=/app/mydata/data --innodb_undo_tablespaces=3 --explicit_defaults_for_timestamp ``` 这些步骤将会安装并初始化MySQL 5.7的二进制版本。请确保按照指定的路径和命令进行操作,以确保安装过程顺利完成。<span class="em">1</span><span class="em">2</span><span class="em">3</span> #### 引用[.reference_title] - *1* *2* *3* [MySQL5.7 二进制安装](https://blog.csdn.net/weixin_68330286/article/details/124588446)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 100%"] [ .reference_list ]
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值