Linux install mysql 5.6.5 (a dumb installation tutorial)

1. Check if it is installed (delete if there is one)

rpm -qa | grep mysql   # 查询安装,有的话会出来一个列表

rpm -e mysql                   # 普通删除(mysql 替换为查出的包名)
rpm -e --nodeps mysql          # 强制删除(mysql 替换为查出的包名)

2. Install mysql (yml mode)


wget http://repo.mysql.com/mysql-community-release-el7-5.noarch.rpm  # 下载rpm 资源包
rpm -ivh mysql-community-release-el7-5.noarch.rpm                    # 安装rpm 资源包
yum install mysql-server                                             # 正式下载 mysql

chown mysql:mysql -R /var/lib/mysql          # 设置权限 
mysqld --initialize                          # 初始化mysql   
systemctl start mysqld                       # 启动mysql
systemctl status mysqld                      # 查看mysql 启动状态  
mysqladmin --version                         # 检查是否安装成功(查看版本信息)             

Error:
ERROR 2002 (HY000): of Can not Connect to local MySQL Server through socket '/var/lib/mysql/mysql.sock' (2)
in the implementation of mysqlthe command to enter, no password is set to come out, using the mysqlcommand The above error will occur

rm -rf /var/lib/mysql      # 删除初始化相关的配置信息
mysqld --initialize        # 初始化mysql   
systemctl start mysqld     # 启动mysql

Three, set password-use MySQL Client

mysql>  mysql               # 默认无密码,直接可进入mysql内部
mysql>  SHOW DATABASES;     # 查询所有数据表  
mysql>  use mysql;          #  进入mysql 数据表
mysql>  SET PASSWORD FOR 'root'@'localhost' = PASSWORD('root123456');    #  修改密码为 root123456

Exit mysql, log in with password

mysql>  mysql -u root -p     # 登录mysql, 回车输入密码在回车
Enter password:*******

Four, set to allow remote connection

mysql -u root -p                     # 登录mysql

# 设置允许所有ip连接,  root123456 为密码
mysql> GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY 'root123456' WITH GRANT OPTION;


mysql> use mysql;                    # 进入mysql 数据表
mysql> select host user from user;   # 查看权限
mysql> flush privileges;             # 刷新权限

Five, start and close the command

service mysql start    # 启用
service mysql stop     # 停止

6. Firewall (If the remote connection fails, pay attention)

The firewall opens port 3306

chkconfig iptables on     # 永久开启
chkconfig iptables off    # 永久关闭

service iptables start    # 即时开启
service iptables stop     # 即时关闭

The firewall cannot find the iptables file processing.
Turn off the firewall and cannot find the iptables file. The solution is as follows, because the firewall is used as the firewall by default, stop it and install an iptable

systemctl stop firewalld 
systemctl mask firewalld
yum install -y iptables 
yum install iptables-services
  • This is the end of this article. If you find it useful, please like or pay attention to it. We will continue to update more content from time to time... Thank you for watching!

  • Personal open source project (universal background management system) –> https://gitee.com/wslxm/spring-boot-plus2 , you can see if you like, thank you

Guess you like

Origin blog.csdn.net/qq_41463655/article/details/109433642