二进制包安装mysql

二进制包安装mysql

准备

1.先查看系统中是否已存在mysql,存在将其卸载

rpm -qa mysql
rpm -qa mariadb
yum remove xxx -y

2.环境清理 清空PATH有关的mysql 注释掉之前的$PATH 没有就跳过这步

#export PATH=/application/mysql/bin:$PATH

3.安装所需的基础依赖

yum install ncurses-devel libaio-devel gcc make cmake -y

4.创建用户

useradd -s /sbin/nologin -M mysql

实验步骤

mysql官网下载

1.下载二进制安装包

自行选择一个下载目录 这里我下载到/opt下

wget https://cdn.mysql.com/archives/mysql-5.6/mysql-5.6.40-linux-glibc2.12-x86_64.tar.gz

4.解压到/usr/local/

tar -zxvf mysql-5.6.40-linux-glibc2.12-x86_64.tar.gz -C /usr/local

cd /usr/local/

mv mysql-5.6.40-linux-glibc2.12-x86_64/ mysql

5.mysql下面没有data目录则创建

mkdir /usr/local/mysql/data

6.修改属主属组

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

7.创建/etc/my.cnf文件

vim /etc/my.cnf
[mysqld]
port=3306
basedir=/usr/local/mysql
datadir=/usr/local/mysql/data
socket=/usr/local/mysql/mysql.sock
character-set-server=utf8
log-error=/var/log/mysqld.log
pid-file=/tmp/mysqld.pid

[mysql]
socket=/usr/local/mysql/mysql.sock

[client]
socket=/usr/local/mysql/mysql.sock

8.初始化

/usr/local/mysql/scripts/mysql_install_db --defaults-file=/etc/my.cnf --basedir=/usr/local/mysql/ --datadir=/usr/local/mysql/data --user=mysql

9.配置环境变量

vim /etc/profile
export PATH=/usr/local/mysql/bin:$PATH

10.复制启动脚本 修改脚本 启动

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

修改配置文件
vim /etc/init.d/mysqld

在46行 47行 补全路径
basedir=/usr/local/mysql
datadir=/usr/local/mysql/data

执行脚本启动mysql
[root@localhost support-files]# /etc/init.d/mysqld start
Starting MySQL. SUCCESS!

11.将mysql添加到系统服务

先关闭服务
/etc/init.d/mysqld stop
vim /usr/lib/systemd/system/mysql.service

注意这里的路径要跟你的安装路径一致 pid文件路径可以通过 开启mysql服务时 ps -ef | grep mysql来查看
PIDFile=/tmp/mysqld.pid
ExecStart=/usr/local/mysql/support-files/mysql.server start

[Unit]
Description=Mysql
After=syslog.target network.target remote-fs.target nss-lookup.target

[Service]
Type=forking
PIDFile=/tmp/mysqld.pid
ExecStart=/usr/local/mysql/support-files/mysql.server start
ExecReload=/bin/kill -s HUP $MAINPID
ExecStop=/bin/kill -s QUIT $MAINPID
PrivateTmp=false

[Install]
WantedBy=multi-user.target
systemctl daemon-reload
systemclt start mysql

12.测试,并修改root密码

启动mysql
/etc/init.d/mysqld start

执行命令 默认没有密码直接回车
mysql -uroot -p

修改密码 先退出mysql
exit
第一次输入密码直接回车 因为没有设置密码 第二次输入你想设置的密码 第三次再次输入密码确认
[root@localhost mysql]# mysqladmin -uroot -p password
Enter password: 
New password: 
Confirm new password: 
[root@localhost mysql]# 

13.远程登陆授权
指定网段内192.168.70.*

先登录mysql
mysql -uroot -p

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

flush privileges;

14.远程授权后可以再开一台虚拟机进行连接测试

[root@localhost opt]# mysql -uroot -p -h192.168.70.24

热门相关:流鱼无恙   神算大小姐   豪门情变,渣总裁滚远点!   拒嫁豪门,前妻太抢手   大妆