1.查看是否安装了MySQL数据库
# rpm -qa | grep mysql
<--------------------------------------------
将剩余mysql目录删除干净(安装失败后尝试)
复制代码
[root@node2 mysql-5.7.26]# find / -name mysql
/etc/selinux/targeted/active/modules/100/mysql
/var/lib/mysql
/var/lib/mysql/mysql
/usr/share/mysql
--------------------------------------------->
2.卸载过程
首先需要先停止mysqld服务,否则直接卸载rpm包后,重新安装的mysql没有初始密码
[root@node2 mysql-5.7.26]# service mysqld stop
[root@node2 mysql-5.7.26]# rpm -qa|grep mysql
卸载有两种方式,一种是普通删除,另一种是强力删除,当MySQL数据库有其它的依赖文件时,也进行删除。
rpm -e mysql和rpm -e --nodeps mysql
3.安装过程
首先,我们通过命令:yum list | grep mysql来查看yum上提供的数据库可下载版本。
32位系统 选择安装 mysql.i686,mysql-devel.i686,mysql-server.i686就行了。
64位系统 选择安装 mysql.x86_64 mysql-server.x86_64 mysql-devel.x86_64
yum -y install mysql.x86_64 mysql-server.x86_64 mysql-devel.x86_64
4.启动mysql
启动方式:service mysqld start 第一次启动会初始化数据库
关闭方式:service mysqld stop
启动报错
Initializing MySQL database:
FATAL ERROR: Could not find mysqld
The following directories were searched:
/usr/local/mysql/libexec
/usr/local/mysql/sbin
/usr/local/mysql/bin
If you compiled from source, you need to run 'make install' to
copy the software into the correct location ready for operation.
If you are using a binary release, you must either be at the top
level of the extracted archive, or pass the --basedir option
pointing to that location.
[FAILED]
yum安装时警告warning: /etc/my.cnf created as /etc/my.cnf.rpmnew
由于原来的/etc/my.cnf存在,安装前应该删除
我们可以使用命令:
chkconfig --list | grep mysqld 来查看是否开机自动启动。如果2~5的都是 on 或者是启用
说明是开机自动启动,否则如果不是。我们可以通过命令
chkconfig mysqld on 来设置成开机自动启动。
5.修改root密码
进入mysql 至此mysql安装完毕
mysql
如果报错-bash: /usr/local/mysql/bin/mysql: No such file or directory
mkdir /usr/local/mysql/bin/ -p
cp /usr/bin/mysql /usr/local/mysql/bin/
退出mysql 修改密码(此时只是退出mysql,不能关掉mysql服务,否则将修改失败)
修改root密码
/usr/bin/mysqladmin -u root password 你的密码
6.远程连接设置
首先要开放 3306 端口 打开防火墙文件
vim /etc/sysconfig/iptables
开放3306端口
-A INPUT -p tcp -m state --state NEW -m tcp --dport 3306 -j ACCEPT
重启iptables服务
service iptables restart;
进入mysql,授权远程连接
GRANT ALL PRIVILEGES ON . TO ‘root’@’%’ IDENTIFIED BY ‘root’ WITH GRANT OPTION;
FLUSH PRIVILEGES;
GRANT ALL PRIVILEGES ON . TO 'root'@'%' IDENTIFIED BY 'root' WITH GRANT OPTION;
刷新权限
flush privileges;
mysql>use mysql;
mysql>update user set host = '%' where user = 'root';
mysql>select host, user from user;
如果本地能连接上,远程无法连接,查看root密码与本地密码是否一致