1.检测是否安装过mysql,使用命令
rpm -qa | grep mysql
2.查看mysql残留数据信息
find / -name mysql
3.删除对应文件件和数据
rm -rf mysql
4.下载要安装的mysql安装包
mysql-5.7.19-linux-glibc2.12-x86_64.tar.gz
5.解压
tar -zxvf mysql-5.7.19-linux-glibc2.12-x86_64.tar.gz
6.将解压好的文件移动到/usr/local 并从命名为mysql
mv mysql-5.7.19-linux-glibc2.12-x86_64 /usr/local/mysql
7.在mysql目录下创建data文件夹,用于保存数据
mkdir data
8.创建mysql的用户组和用户
groupadd mysql
useradd -r -g mysql mysql
9.修改mysql目录的权限
chown -R mysql:mysql /usr/local/mysql
10.进入mysql 的bin目录,初始化mysql
./mysqld --user=mysql --initialize --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data
需要记录初始化密码:
11.打开vim /etc/my.cnf,修改内容为:
[mysqld]
datadir=/usr/local/mysql/data/
socket=/usr/local/mysql/data/mysql.sock
# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0
# Settings user and group are ignored when systemd is used.
# If you need to run mysqld under a different user or group,
# customize your systemd unit file for mariadb according to the
# instructions in http://fedoraproject.org/wiki/Systemd
#[mysqld_safe]
#log-error=/var/log/mariadb/mariadb.log
#pid-file=/var/run/mariadb/mariadb.pid
#
# include all files from the config directory
#
#!includedir /etc/my.cnf.d
[mysql]
socket=/usr/local/mysql/data/mysql.sock
12.将mysql加入开机自动启动
[root@VM_0_4_centos mysql]# cp support-files/mysql.server /etc/init.d/mysql
[root@VM_0_4_centos mysql]# chmod +x /etc/init.d/mysql
[root@VM_0_4_centos mysql]# chkconfig --add mysql
[root@VM_0_4_centos mysql]# chkconfig --list
13.添加mysql环境变量,打开/etc/profile加入:
export PATH=$PATH:/usr/local/mysql/bin:/usr/local/lib
14.修改登录密码,用初始密码登录mysql,然后执行:
alter user 'root'@'localhost' identified by '123456';
不然执行sql语句会提示: