surroundings
- Centos7.4
tool
- Xshell (remote terminal emulation)
- FileZilla (linux to transfer files)
Ready to work
1. Uninstall MariaDB
Note: Be sure to mariaDB package and the package comes with mysql clean uninstall, or a variety of wonderful installation errors, leading to failure.
rpm -qa | grep -i mariadb //查看有没有安装mariadb
rpm -e --nodeps mariadb-libs-5.5.56-2.el7.x86_64 //如果有,卸载MariaDB
2, remove the existing Mysql
//卸载旧版本的Mysql
rpm -qa | grep -i mysql //查看有没有安装mysql
rpm -e MySQL-client-5.6.38-1.el7.x86_64 //如果有,卸载旧版本Mysql
//删除服务
chkconfig --list | grep -i mysql //查看服务
chkconfig --del mysql //删除服务
//删除mysql分散的文件夹
whereis mysql //查出相应的mysql文件夹,也可以用find / -name *mysql*
rm -rf /use/lib/mysql //删除
3, mounted reliance
Note: The first installed dependence, then install mysql. Even if the order go wrong, Bahrain relies must uninstall and reinstall mysql mysql, mysql otherwise fitted with a variety of error also occurs
yum install perl
yum -y install autoconf //此包安装时会安装Data:Dumper模块
4, download mysql
Note: centos kernel based on Red Hat, so the download time to download Red Hat version
centos 7.2_64 bit unclear if the number of bits of their own system, you can view by file / bin / ls
5, the user group to increase mysql
cat /etc/group |grep mysql //检查mysql用户及组是否存在,如果没有执行下面命令
groupadd mysql //创建组
useradd -r -g mysql mysql //创建用户并把该用户加入到组mysql,这里的 -r是指该用户是内部用户,不允许外部登录
passwd mysql //给用户mysql设置密码,需要输入2次
installation
1, the installation Mysql
解压mysql
tar -xvf MySQL-5.6.38-1.el7.x86_64.rpm-bundle.tar //注意,是-xvf不是-zxvf
安装mysql
rpm -ivh MySQL-client-5.6.38-1.el7.x86_64.rpm //-i是安装,-v是列出更多详细信息,-h是在安装时列出hash标记
rpm -ivh MySQL-devel-5.6.38-1.el7.x86_64.rpm
rpm -ivh MySQL-server-5.6.38-1.el7.x86_64.rpm
2, change passwords
service mysql status //查看mysql服务状态
//如果是开启服务状态,用service mysql status关闭服务
mysqld_safe --user=mysql --skip-grant-tables --skip-networking & //绕过密码登录
mysql -u root -p //登录
use mysql //切换数据库
select Host,User,Password from user; //查询用户 UPDATE user SET password=password("root") WHERE user='root'; //修改密码 quit //退出
service mysql restart //重启mysql服务
mysql -u root -proot // -proot,p代表password,root是密码
use mysql //切换数据库
set password = password('root'); //第一次登陆必须修改mysql密码 flush privileges; //刷新权限
//赋予任何主机访问数据的权限(远程访问)
grant all privileges on *.* to 'root'@'%' identified by 'root' with grant option; flush privileges; //刷新权限 quit //退出 mysql service mysql restart //重启mysql
3, open the firewall to open port 3306 (Centos7 above is managed by the firewall)
//查看firewall状态(runing:运行,not runing:没有运行),如果没有运行,用systemctl start firewalld启动
firewall-cmd --state
firewall-cmd --permanent --zone=public --add-port=3306/tcp //添加3306端口 firewall-cmd --reload //重新加载firewall
4, set the mysql boot
chkconfig --list mysql //查看mysql服务
chkconfig mysqld on //开启MySQL服务自动开启命令
chkconfig mysql on //开启MySQL服务自动开启命令
mysql set of important directories
- / Var / lib / mysql database file
- / Usr / share / mysql command and configuration file
- / Usr / bin mysqladmin, mysqldump commands
Reprinted from https://segmentfault.com/a/1190000012622747