一、查找删除老版本mysql
# whereis mysql
# find / -name mysql
/etc/selinux/targeted/active/modules/100/mysql
/usr/lib64/mysql
/usr/share/mysql
---------------------------------------
rm -rf /etc/selinux/targeted/active/modules/100/mysql
rm -rf /usr/lib64/mysql
rm -rf /usr/share/mysql
rm -rf /etc/my.cnf
rm -rf /etc/my.cnf.d
----------------------------------------
如果有必要,删除mysql用户以及mysql用户组。
# more /etc/passwd | grep mysql
mysql:x:101:501::/home/mysql:/bin/bash
# more /etc/shadow | grep mysql
mysql:!!:16496::::::
# more /etc/group | grep mysql
mysql:x:501:
# userdel mysql
# groupdel mysql
groupdel: group mysql does not exist
#
确认MySQL是否卸载删除
# rpm -qa | grep -i mysql
二、安装
# wget https://cdn.mysql.com//Downloads/MySQL-5.7/mysql-5.7.19-linux-glibc2.12-x86_64.tar.gz
# yum install libaio numactl -y [安装MySQL依赖]
# tar -zxvf mysql-5.7.19-linux-glibc2.12-x86_64.tar.gz -C /usr/local
# cd /usr/local
# mv mysql-5.7.19-linux-glibc2.12-x86_64 mysql
三、配置
# groupadd mysql
# useradd -r -g mysql -s /bin/false mysql/因为用户只需要所有权不需要登录,useradd命令使用-r和-s /bin/false选项创建一个用户没有登录服务器的权限
在mysql目录下创建文件夹mysql-files:
# mkdir /usr/local/mysql/mysql-files
# chmod 750 /usr/local/mysql/mysql-files //修改mysql-files的权限
# chown -R mysql:mysql /usr/local/mysql //修改mysql目录下所有文件权属关系
初始化/usr/local/mysql/data目录:
# cd /usr/local/mysql
# bin/mysqld --initialize --user=mysql //*在5.7.6版本以前使用:bin/mysql_install_db --user=mysql*//
【出现错误libnuma.so.1: cannot open shared】#yum install numactl -y
千万记住初始化生成的临时密码,否则又要悲催的干很多事了。。。
如果您希望服务器能够自动部署支持安全连接,使用mysql_ssl_rsa_setup实用程序来创建缺省SSL和RSA文件:
# bin/mysql_ssl_rsa_setup
开机自启动
centos7 #vim /usr/lib/systemd/system/mysql.service
--------------------------------------------------
[Unit]
Description=mysql
After=network.target remote-fs.target nss-lookup.target
[Service]
Type=forking
ExecStart=/usr/local/mysql/support-files/mysql.server start
#ExecReload=/usr/local/mysql/support-files/mysql.server restart
#ExecStop=/usr/local/mysql/support-files/mysql.server stop
#PrivateTmp=true
[Install]
WantedBy=multi-user.target
--------------------------------------------------
# chmod 754 /usr/lib/systemd/system/mysql.service
#systemctl enable nginx.service
#systemctl start nginx.service【运行mysql】
登录mysql:mysql -u root -p 生成的临时密码
注:在mysql5.7.18版本文件中不再包含my-default.cnf文件了
#vi /usr/local/mysql/my.cnf
--------------------------------
[client]
port = 1226
#socket = /var/lib/mysql/mysql.sock
default-character-set=utf8
[mysqld]
port = 1226
#socket = /var/lib/mysql/mysql.sock
character-set-server=utf8
[mysql]
#no-auto-rehash
auto-rehash
default-character-set=utf8
-----------------------------------
#firewall-cmd --zone=public --add-port=1226/tcp --permanent【添加防火墙】
#firewall-cmd --reload 【重启防火墙】
修改密码
#mysql -u root -p
输入密码
mysql> SET PASSWORD FOR 'root'@'localhost' = PASSWORD('newpass');
允许其他ip登录
mysql>GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY '用户的密码' WITH GRANT OPTION;
----------------
FLUSH PRIVILEGES;
退出mysql数据库:
exit
----------------
开机自启动
centos7 #vim /usr/lib/systemd/system/mysql.service
--------------------------------------------------
[Unit]
Description=mysql
After=network.target remote-fs.target nss-lookup.target
[Service]
Type=forking
ExecStart=/usr/local/mysql/support-files/mysql.server start
#ExecReload=/usr/local/mysql/support-files/mysql.server restart
#ExecStop=/usr/local/mysql/support-files/mysql.server stop
#PrivateTmp=true
[Install]
WantedBy=multi-user.target
--------------------------------------------------
# chmod 754 /usr/lib/systemd/system/mysql.service
#systemctl enable nginx.service
##systemctl restart nginx.service 【重启mysql】
centos6 #将mysql启动脚本放入所有脚本运行目录/etc/rc.d/init.d中
2 cp /lamp/mysql-5.0.41/support-files/mysql.server /etc/rc.d/init.d/mysqld
3
4 #改变权限
5 chown root.root /etc/rc.d/init.d/mysqld
6
7 #所有用户都可以执行,单只有root可以修改
8 chmod 755 /etc/rc.d/init.d/mysqld
9
10 #将mysqld 放入linux启动管理体系中
11 chkconfig --add mysqld
12
13 #查看全部服务在各运行级状态
14 chkconfig --list mysqld
15
16 #只要运行级别3启动,其他都关闭
17 chkconfig --levels 245 mysqld off
华旅网络 |