一:卸载已安装的mysql
1.关闭服务mysql进程
systemctl stop mysql.service
2.查找mysql的目录并彻底删除
find / -name mysql
3.执行删除
rm -rf mysql
3.删除mysql配置文件my.cnf
rm -rf /etc/my.cnf
4.删除mysql配置文件mysqld
rm -rf /etc/init.d/mysqld
5.删除mysql用户及用户组
userdel mysql
二:Linux下安装Mysql
1.下载安装包
mysql-5.6.16-linux-glibc2.5-x86_64.tar.gz
2.解压安装包
tar -zxvf mysql-5.6.16-linux-glibc2.5-x86_64.tar.gz
3.添加系统mysql用户组及用户
groupadd mysql和useradd -r -g mysql mysql
4.重命名文件
mv mysql-5.6.16-linux-glibc2.5-x86_64 mysql
5.进入mysql目录
cd /usr/local/mysql
6.修改当前目录拥有者为mysql用户
chown -R mysql:mysql ./
7.安装数据库(yum install perl-Data-Dumper)
yum -y install perl perl-devel
yum install -y perl-Data-Dumper
./scripts/mysql_install_db --user=mysql
8.修改当前目录拥有者为root用户
chown -R root:root ./
9.修改当前data目录拥有者为mysql
chown -R mysql:mysql ./data
10.进入support-files目录
cd support-files
11.把启动脚本放到初始化目录
cp my-default.cnf /etc/my.cnf;cp mysql.server /etc/init.d/mysqld
12.启动服务
service mysqld start
13.修改密码
/usr/local/mysql/bin/mysqladmin -u root -p password 123456(不输入密码,直接回车)
14.进入mysql
/usr/local/mysql/bin/mysql -u root -p
15.配置远程访问
grant all privileges on *.* to root @"%" identified by '123456' WITH GRANT OPTION
可用(后台发现)
mysql> use mysql;
mysql> GRANT ALL ON *.* TO admin@'%' IDENTIFIED BY 'admin' WITH GRANT OPTION;
16.刷新
关闭防火墙((暂时关闭)--- systemctl stop firewalld (永久关闭)--- systemctl disable firewalld.service)
flush privileges
17.把mysql客户端放入默认路径下
ln -s /usr/local/mysql/bin/mysql /usr/local/bin/mysql
(可用)
ln -s /usr/local/mysql/bin/mysql /usr/bin
18.主机访问
mysql -h192.168.171.128 -uroot -p
19.配置开机启动
先将/usr/local/mysql/mysql/support-files/ 文件夹下的mysql.server文件复制到 /etc/rc.d/init.d/ 目录下mysqld
命令: cp /usr/local/mysql/support-files/mysql.server /etc/rc.d/init.d/mysqld
赋予可执行权限:chmod +x /etc/init.d/mysqld
添加为服务: chkconfig --add mysqld
查看服务列表: chkconfig --list