二进制包安装mysql准备

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

rpm -qa mysqlrpm -qa mariadbyum 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/localcd /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=3306basedir=/usr/local/mysqldatadir=/usr/local/mysql/datasocket=/usr/local/mysql/mysql.sockcharacter-set-server=utf8log-error=/var/log/mysqld.logpid-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/profileexport 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/mysqldatadir=/usr/local/mysql/data执行脚本启动mysql[root@localhost support-files]# /etc/init.d/mysqld startStarting MySQL. SUCCESS!

11.将mysql添加到系统服务

先关闭服务/etc/init.d/mysqld stopvim /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=MysqlAfter=syslog.target network.target remote-fs.target nss-lookup.target[Service]Type=forkingPIDFile=/tmp/mysqld.pidExecStart=/usr/local/mysql/support-files/mysql.server startExecReload=/bin/kill -s HUP $MAINPIDExecStop=/bin/kill -s QUIT $MAINPIDPrivateTmp=false[Install]WantedBy=multi-user.target
systemctl daemon-reloadsystemclt start mysql

12.测试,并修改root密码

启动mysql/etc/init.d/mysqld start执行命令 默认没有密码直接回车mysql -uroot -p修改密码 先退出mysqlexit第一次输入密码直接回车 因为没有设置密码 第二次输入你想设置的密码 第三次再次输入密码确认[root@localhost mysql]# mysqladmin -uroot -p passwordEnter password: New password: Confirm new password: [root@localhost mysql]# 

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

先登录mysqlmysql -uroot -pgrant all privileges on *.* to root@'192.168.70.%' identified by '123456';flush privileges;

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

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