我系统是centos7.5,安装的mysql版本是mysql-5.7.38
下载地址:https://dev.mysql.com/downloads/mysql/#downloads
rpm -qa | grep -i mysql
find / -name mysql
rm -rf /home/mysql
rm -rf /home/mysql/mysql-5.6.33-linux-glibc2.5-x86_64/bin/mysql
rm -rf /home/mysql/mysql-5.6.33-linux-glibc2.5-x86_64/include/mysql
rm -rf /etc/selinx/targeted/active/modules/100/mysql
rm -rf /var/spool/mail/mysql
rm -rf /usr/lib64/mysql
rm -rf /usr/share/mysql
rm -rf /usr/local/mysql
rm -rf /usr/local/mysql/data/mysql
rm -rf /usr/local/mysql/data/mysql/mysql
rm -rf /usr/local/mysql/bin/mysql
rm -rf /usr/localmysql/include/mysql
rm -rf /usr/local/mysql/mysql
#查看
rpm -qa|grep mariadb
#删除
yum remove mariadb-libs
tar -zxvf mysql-5.7.38-el7-x86_64.tar.gz
mv mysql-5.7.38-el7-x86_64/ /usr/local/mysql
注意:
这步会将mysql-5.7.38-el7-x86_64重命名为mysql并放到/usr/local目录下
#添加组
groupadd mysql
#添加用户
useradd -g mysql mysql
#将文件的所有属性改为mysql用户
chown -R mysql /usr/local/mysql
查看添加的mysql用户情况:
id mysql
进入目录/usr/local/mysql/support-files/发现没有my_default.cnf文件,自己从网上找了个,改成自己需要的配置,放到**/etc/my.cnf**
my.cnf
[mysqld]
#设置mysql的安装目录
basedir =/usr/local/mysql
#设置mysql数据库的数据存放目录
datadir = /usr/local/mysql/data
#设置端口
port = 3306
socket = /tmp/mysql.sock
#设置字符集
character-set-server=utf8
#日志存放目录
log-error = /usr/local/mysql/data/mysqld.log
pid-file = /usr/local/mysql/data/mysqld.pid
#允许时间类型的数据为零(去掉NO_ZERO_IN_DATE,NO_ZERO_DATE)
sql_mode=ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION
default-time_zone = '+8:00'
max_allowed_packet = 20M
在/usr/local/mysql目录下初始化mysql
cd /usr/local/mysql
./bin/mysqld --initialize --user=mysql --basedir=/usr/local/mysql/ --datadir=/usr/local/mysql/data/
cat /usr/local/mysql/data/mysqld.log
./mysql.server start
#进入/usr/local/mysql/bin目录
cd /usr/local/mysql/bin
#登录mysql
./mysql -uroot -p
输入第9步得到的mysql密码
mysql>set password for root@localhost = password('root');
mysql>GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY 'root' WITH GRANT OPTION;
mysql>FLUSH PRIVILEGES;
mysql>exit;
#复制mysql.server到/etc/init.d/重命名为mysqld
cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld
#将mysql注册为开启启动的服务
chkconfig --add mysqld
service mysql start
service mysql stop
service mysql restart
service mysql status
也可以使用:
#启动
systemctl start mysql
#停止
systemctl stop mysql
#重启
systemctl restart mysql
#查看状态
systemctl status mysql