linux安装mysql常出现的问题

wget http://repo.mysql.com/mysql-community-release-el7-5.noarch.rpm

rpm -ivh mysql-community-release-el7-5.noarch.rpm

yum update

yum install mysql-server

权限设置:

chown -R mysql:mysql /var/lib/mysql/

初始化 MySQL:

mysqld --initialize

查看 MySQL 运行状态:systemctl status mysqld

启动mysql服务 重要:systemctl start mysqld

启动mysql服务报错

Loaded: loaded (/usr/lib/systemd/system/mysqld.service; disabled; vendor preset: disabled)

Active: failed (Result: exit-code) since Wed 2025-04-09 19:05:37 CST; 3min 23s ago

Process: 324472 ExecStopPost=/usr/libexec/mysql-wait-stop (code=exited, status=0/SUCCESS)

Process: 324444 ExecStart=/usr/libexec/mysqld --basedir=/usr (code=exited, status=1/FAILURE)

Process: 324354 ExecStartPre=/usr/libexec/mysql-prepare-db-dir mysqld.service (code=exited, status=0/SUCCESS)

Process: 324303 ExecStartPre=/usr/libexec/mysql-check-socket (code=exited, status=0/SUCCESS)

Main PID: 324444 (code=exited, status=1/FAILURE)

Status: "Server startup in progress"

Error: 2 (没有那个文件或目录)

解决办法:

chmod -R 777 /var/lib/mysql

使用以下命令来创建root用户的密码

mysqladmin -u root password "123456";

mysql -u root -p

密码相关问题

vim /etc/my.cnf

mysqld

skip-grant-tables #添加此行,跳过密码验证,忽略权限表身份验证

重启

systemctl restart mysqld

直接进入mysql

mysql

show databases;

describe mysql.user;

select host,user,authentication_string from mysql.user;

更改密码

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

在 MySQL 5.7 及更高版本中,使用以下命令更新密码:

sql

复制

复制代码
ALTER USER 'root'@'localhost' IDENTIFIED BY '123456';

刷新授权

flush privileges;

quit

注释掉跳过密码

vim /etc/my.cnf

再次重启 MySQL 服务

bash

复制代码
systemctl restart mysqld

登录mysql

mysql -uroot -p123456

相关推荐
跟橙姐学代码4 分钟前
学Python别死记硬背,这份“编程生活化笔记”让你少走三年弯路
前端·python
椰子今天很可爱28 分钟前
静态库和动态库
linux
檀越剑指大厂1 小时前
【Linux系列】如何在 Linux 服务器上快速获取公网
linux·服务器·php
共享家95271 小时前
linux-高级IO(上)
java·linux·服务器
站大爷IP1 小时前
Python与MySQL:从基础操作到实战技巧的完整指南
python
老歌老听老掉牙1 小时前
SymPy 矩阵到 NumPy 数组的全面转换指南
python·线性代数·矩阵·numpy·sympy
Java水解1 小时前
MySQL 亿级数据表平滑分表实践:基于时间分片的架构演进
后端·mysql
站大爷IP1 小时前
Python条件判断:从基础到进阶的实用指南
python
赛博郎中1 小时前
pygame小游戏飞机大战_8继承精灵玩家优化
python·pygame
William一直在路上1 小时前
Python数据类型转换详解:从基础到实践
开发语言·python