centos7安装mysql数据库并且授权问题

本文详细介绍在CentOS7上安装MySQL数据库的过程,包括通过yum源安装Mariadb或MySQL的方法,以及解决安装过程中可能出现的问题,如错误代码140524、连接本地MySQL服务器失败等,并提供设置root密码及远程授权的步骤。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

centos7安装数据库步骤

首先两种安装方式,第一种通过yum源安装mariadb;第二种通过安装mysql;

yum -y install mysql
yum -y install mariadb-server
mysql_secure_installation 设置 root密码等相关

 当出现报错信息如下:

140524 03:15:57 mysqld_safe Starting mysqld daemon with databases from /var/lib/mysql
140524  3:15:57 [ERROR] Can't open the mysql.plugin table. Please run mysql_upgrade to create it.
140524  3:15:57  InnoDB: Initializing buffer pool, size = 8.0M
140524  3:15:57  InnoDB: Completed initialization of buffer pool
140524  3:15:57  InnoDB: Started; log sequence number 0 44233
140524  3:15:57 [ERROR] Fatal error: Can't open and lock privilege tables: Table 'mysql.host' doesn't exist
140524 03:15:57 mysqld_safe mysqld from pid file /var/run/mysqld/mysqld.pid ended
解决办法mysql_install_db
--user=mysql --ldata=/var/lib/mysql/

当出现

ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2)
把这个/var/lib/mysql路径下清空;

systemctl start mysqld.service

systemctl status mysqld.service

当出现Failed to start mysqld.service: Unit mysqld.service failed to load: No such file or directory

systemctl start mariadb.service

systemctl enable mariadb.service

 

强制进行修改密码

systemctl stop mysqld;

systemctl set-environment MYSQLD_OPTS="--skip-grant-tables";

systemctl start mysqld;

mysql -u root;

use mysql;

update user set password=password('1234!@#$abc') where user='root' and host='localhost';  
FLUSH PRIVILEGES; 

 远程授权数据库登陆:

grant all privileges on *.* to 'root’@’192.168.4.14’ identified by ‘1234!@#$abc’ with grant option;

grant all privileges on *.* to 'root’@’10.255.3.3’ identified by ‘1234!@#$abc’ with grant option;

 

 

 

 

 

转载于:https://www.cnblogs.com/haoxinchen/p/9664461.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值