mysql和yum链接放在阿里云盘,链接在下方Linux部署mysql_yum https://www.aliyundrive.com/s/TSwYgZwnKhq 提取码: zt78 点击链接保存,或者复制本段内容,打开「阿里云盘」APP ,无需下载极速在线查看,视频原画倍速播放。
如果mysql下载后有错误,请在线留言,及时补发新的链接
一、下载程序
Linux部署mysql_yum https://www.aliyundrive.com/s/TSwYgZwnKhq 提取码: zt78 点击链接保存,或者复制本段内容,打开「阿里云盘」APP ,无需下载极速在线查看,视频原画倍速播放。
二、环境检查
检测系统是否自带mysql
-
rmp -qa|grep mysql
如果有进行强行卸载
-
rpm -e --nodeps mysql-libs-5.1.52-1.el6_0.1.x86_64
查看是否安装mysql
mysql -version
三、mysql安装
用连接工具将下载的mysql-5.7.38-linux-glibc2.12-x86_64.tar.gz上传到linux服务器的/sdsh/software/mysql(自己指定位置,我放在/sdsh/software/mysql下)目录下面(逐行执行)
cd /sdsh/software/mysql
tar -zxvf mysql-5.7.38-linux-glibc2.12-x86_64.tar.gz(链接中的文件是已经解压后的,跳过这个解压的命令)
mv mysql-5.7.38-linux-glibc2.12-x86_64 mysql
cat /etc/group|grep mysql
groupadd mysql
useradd -r -g mysql mysql
mkdir /sdsh/software/mysql/mysql/data
chown -R mysql.mysql /sdsh/software/mysql/mysql/
四、配置yum
用连接工具将下载的libaio-0.3.109-13.el7.x86_64.rpm上传到linux服务器的/sdsh/software/mysql目录下面
rpm -ivh /sdsh/software/mysql/libaio-0.3.109-13.el7.x86_64.rpm
五、在/sdsh/software/mysql/mysql/support-files目录下创建my_default.cnf
cd > /sdsh/software/mysql/mysql/support-files/my_default.cnf
按 a或者i键进入编辑模式(下方出现各--insert标识时,以下内容直接复制进去)
[mysqld]
basedir = /sdsh/software/mysql/mysql
datadir = /sdsh/software/mysql/mysql/data
port = 3306
socket = /tmp/mysql.sock
max_connections=2000
character-set-server=utf8
max_allowed_packet=800M
connect_timeout=60
log-error = /sdsh/software/mysql/mysql/data/mysqld.log
pid-file = /sdsh/software/mysql/mysql/data/mysqld.pid
sql_mode=ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION
编辑完后ESC退出编辑
依次按:wq退出保存文件
cp my_default.cnf /etc/my.cnf
六、初始化数据库
/sdsh/software/mysql/mysql/bin/mysqld --initialize --user=mysql --basedir=/sdsh/software/mysql/mysql/ --datadir=/sdsh/software/mysql/mysql/data/
cat /sdsh/software/mysql/mysql/data/mysqld.log
cp /sdsh/software/mysql/mysql/support-files/mysql.server /etc/init.d/mysql
service mysql start
vim /etc/my.cnf
按 a或者i键进入编辑模式
skip-grant-tables=1(不需要密码登录mysql的命令)
编辑完后ESC退出编辑
按:wq退出文件
service mysql restart
七、修改密码、开通IP访问
/sdsh/software/mysql/mysql/bin/mysql -u root -p
update mysql.user set authentication_string=password('root') where user='root' ;
flush privileges;
grant select on `master`.* to root@localhost identified by 'root';
use mysql;
update user set host='%' where user = 'root';
flush privileges;
exit;
vim /etc/my.cnf
按 a或者i键进入编辑模式
去掉内容 skip-grant-tables=1
编辑完后ESC退出编辑
按:wq退出文件
service mysql restart
八、设置MySql自动启动
cp /sdsh/software/mysql/mysql/support-files/mysql.server /etc/init.d/mysqld
chmod +x /etc/init.d/mysqld
chkconfig --add mysqld
chkconfig --list
如果看到mysql的服务,并且3,4,5都是开的话则成功
如果是关,则键入 chkconfig --level 345 mysqld on
九、设置环境变量
vim /etc/profile
按 a或者i键进入编辑模式
在最上边复制 export PATH=$PATH:/sdsh/software/mysql/mysql/bin
编辑完后ESC退出编辑
按:wq退出文件
service mysql restart
十、变更端口(可选)
mysql -u root -proot
show global variables like 'port';
/etc/init.d/mysqld restart 或者 service mysql restart
vim /etc/my.cnf
按a或i进入编辑模式,定位到port=3306,将3306替换为要变更的端口,按ESC退出编辑,按:wq保存修改
/etc/init.d/mysqld restart 或者 service mysql restart
mysql -u root -proot
show global variables like 'port';
十一、实际项目运行报错的解决
当报错时出现
You can change this value on the server by setting the 'max_allowed_packet' variable.
在查询语句里输入
set global max_allowed_packet = 210241024*10;