Centos7部署MySQL解压版

前期准备(删除系统旧版本留存):

1.关闭mysql服务
service mysqld stop
2.删除mysql目录
whereis mysql ——找到mysql目录
rm -rf xxxxx ——xxxxx代表mysql目录
3.删除mysql相关配置文件
my.cnf
4.后记
此方法针对于网络状况不好的服务器,不是yum或者rpm方法安装mysql的卸载同样有效


新版本部署操作:
1、mysql5.7.32官网下载
https://dev.mysql.com/downloads/mysql/5.7.html
在这里插入图片描述
备注:下载慢可以用迅雷试试

2、上传服务器并解压tar包

tar xzvf xxx.tar.gz

3、解压包改名

mv mysqlXXXX mysql5.7.32

4、建立连接

cd /usr/local
ln -s /opt/mysql5.7.32 mysql

5、进入mysql5.7.32目录创建data文件夹

cd /opt/mysql5.7.32
mkdir data

6、初始化mysql

cd /opt/mysql5.7.32/bin
./mysqld --user=root --basedir=/usr/local/mysql --datadir=/opt/mysql5.7.32/data --initialize
root@localhost: :444)8(gs+gQ

备注:此步骤会产生初始密码,请收好
7、从support-files目录复制mysql.server文件到/etc/init.d/目录,并改名为mysqld

cd support-files/
cp mysql.server /etc/init.d/mysqld

8、修改mysqld配置,指定数据文件目录和数据库base目录,其他内容不变

cd /etc/init.d
vim mysqld

basedir=/usr/local/mysql
datadir=/opt/mysql5.7.32/data

9、新建my.cnf文件,并修改内容

cd /etc
ls -l *cnf
touch my.cnf
vim my.cnf

[client]
port = 3306
default-character-set=utf8
socket=/tmp/mysql.sock

[mysqld]
basedir =/usr/local/mysql
datadir =/opt/mysql5.7.32/data
port = 3306
character-set-server=utf8
socket=/tmp/mysql.sock
default_storage_engine = InnoDB
max_allowed_packet=102400M
lower_case_table_names = 1
max_connections = 3000
open_files_limit = 65535
log_bin_trust_function_creators=1
skip-name-resolve
skip-external-locking
sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES
innodb_file_per_table=1

10、赋权限


useradd mysql
chown -R mysql.mysql /usr/local/mysql/data/

11、修改/etc/profile文件,将/usr/local/mysql/bin加入PATH设置

cd /etc
vim profile

export PATH=$PATH:/usr/local/mysql/bin

source /etc/profile

12、启动mysql,在要求输入密码的时候,输入初始化mysql时最后提示的临时密码XXXX

service mysqld start
mysql -u root -p

如果报mysql安装问题“ERROR 2002 (HY000): Can’t connect to local MySQL server through socket '/tmp/mysql.sock问题,解决方法如下

cd /opt/mysql5.7.32/bin
./mysql -h 127.0.0.1 -u root -p123456a?

13、在mysql命令行,为root用户设置新密码

alter user 'root'@'localhost' identified by '123456a?';

14、检查版本

select version();

15、设置远程连接

mysql -u root -p 解决MySQL 1130错误,无法远程连接
mysql>use mysql;
mysql>select 'host' from user where user='root';
mysql>update user set host = '%' where user ='root';
mysql>flush privileges;

后记:
考虑MySQL主从复制问题在my.cnf中配置如下参数

server_id=28
log-bin=mysql-bin
binlog_format=mixed
relay_log=mysqld-relay-bin
log-slave-updates=ON
Logo

更多推荐