linux安装mysql以及使用navicat连接mysql

目录

一、下载mysql

二、安装mysql

三、使用Navicat连接MySQL

四、常见问题

[1、启动服务时报错 Failed to start mysql.service: Unit not found. 的解决方法。](#1、启动服务时报错 Failed to start mysql.service: Unit not found. 的解决方法。)

[2、登录过程出现:access denied for user'root'@'localhost'(using password:Yes) 的解决方法。](#2、登录过程出现:access denied for user’root’@‘localhost’(using password:Yes) 的解决方法。)

源码等资料获取方法


一、下载mysql

1、获取下载链接

进入官网:https://www.mysql.com

点击downloads --> MySQL Community (GPL) Downloads --> MySQL Community Server 可进入下载界面,选择linux系统,找到自己想要版本右键复制链接地址即可。

比如我获取5.7.28版本的下载链接:https://downloads.mysql.com/archives/get/p/23/file/mysql-5.7.28-linux-glibc2.12-x86_64.tar.gz

2、在linux中使用wget下载

二、安装mysql

解压改名

python 复制代码
tar -xvf mysql-5.7.28-linux-glibc2.12-i686.tar.gz 
mv mysql-5.7.28-linux-glibc2.12-i686 mysql 

添加用户和组

python 复制代码
groupadd mysql 
useradd -r -g mysql mysql 

创建初始化目录和修改目录权限

python 复制代码
mkdir - p /data/mysql 
chown mysql:mysql -R /data/mysql 

修改配置文件 /etc/my.cnf

python 复制代码
[mysqld]
bind-address=0.0.0.0
user=mysql
basedir=/usr/local/mysql
datadir=/data/mysql
log-error=/data/mysql/mysql.err
pid-file=/data/mysql/mysql.pid
character_set_server=utf8mb4  # 设置创建数据库时的默认字符类型
symbolic-links=0

[client]
port=3306
socket=/tmp/mysql.sock

初始化mysql

python 复制代码
cd /usr/local/mysql/bin/
./mysqld --defaults-file=/etc/my.cnf --basedir=/usr/local/mysql --datadir=/data/mysql/ --user=mysql --initialize

设置mysql命令为全局命令:将mysql.server复制到init.d

python 复制代码
[root@localhost support-files]# pwd
/usr/local/mysql/support-files
[root@localhost support-files]# cp mysql.server /etc/init.d/mysql

启动服务

python 复制代码
service mysql start

设置为开机自动启动

python 复制代码
chkconfig mysql on

登录mysql

python 复制代码
mysql -u root -p

到此,mysql安装完毕,并成功登录使用

三、使用Navicat连接MySQL

1、linux防火墙开放3306端口

python 复制代码
[root@node1 ~]# firewall-cmd --add-port=3306/tcp --permanent
[root@node1 ~]# firewall-cmd --reload

如果未开放端口会报错 10060 "Unknown error":

2、开放mysql root用户远端访问权限

在linux中登录mysql,进入mysql库

查看user表中数据,修改root用户host字段值为"%"

python 复制代码
MySQL [mysql]> select host,user from user;
MySQL [mysql]> update user set host="%" where user="root";
MySQL [mysql]> flush privileges;

使用Navicat连接数据库

如果不开放root用户访问权限会报错 not allowed to connect:

四、常见问题

1、启动服务时报错 Failed to start mysql.service: Unit not found. 的解决方法。

2、登录过程出现:access denied for user'root'@'localhost'(using password:Yes) 的解决方法。

1.停止mysql服务:

service mysql stop

2后台安全模式登录mysql;

find / -name mysqld_safe

cd 到文件所在目录

./mysqld_safe --user=mysql --skip-grant-tables --skip-networking

3.新开一个窗口,直接在命令行输入 mysql,登录

4.修改root用户密码:

use mysql

update user set authentication_string=password('123456') where user="root";

注:5.7以上的存储密码的字段变为authentication_string,若上面语句没执行成功执行下面的语句

update mysql.user set password=PASSWORD('123456')where user='root';

5.将密码过期设置为否

update user set password_expired='N' where user="root"

6.刷新、退出:

flush privileges;

quit;

7.重启mysql服务

service mysql restart;

  • 登录时,提示 -bash:mysql:未找到命令

使用yum install -y mysql 安装即可

源码等资料获取方法

各位想获取源码等教程资料的朋友请 点赞 + 评论 + 收藏 ,三连!

三连之后我会在评论区挨个私信发给你们~

相关推荐
码出钞能力9 分钟前
linux内核模块的查看
linux·运维·服务器
星辰云-40 分钟前
# Linux Centos系统硬盘分区扩容
linux·运维·centos·磁盘扩容
聽雨2371 小时前
02每日简报20250704
linux·科技·金融·生活·社交电子·娱乐·媒体
KellenKellenHao1 小时前
MySQL数据库主从复制
数据库·mysql
Maki Winster2 小时前
Peek-Ubuntu上Gif录制工具-24.04LTS可装
linux·ubuntu·peek
qq_171538852 小时前
TCP/IP协议精解:IP协议——互联网世界的邮政编码系统
网络·网络协议·tcp/ip
珹洺2 小时前
计算机网络:(七)网络层(上)网络层中重要的概念与网际协议 IP
网络·tcp/ip·计算机网络
SH11HF2 小时前
小菜狗的云计算之旅,今天学习MySQL数据库基础知识及操作
adb
一只fish2 小时前
MySQL 8.0 OCP 1Z0-908 题目解析(16)
数据库·mysql
兮动人2 小时前
获取终端外网IP地址
java·网络·网络协议·tcp/ip·获取终端外网ip地址