centos安装mysql
2023-04-04 本文已影响0人
嗯o哼
一、安装
mysql官网找到你要安装的mysql版本
我安装的是mysql8
wget https://repo.mysql.com/mysql80-community-release-el7-7.noarch.rpm
服务器上执行命令会下载文件到当前文件夹
然后执行命令
rpm -ivh mysql80-community-release-el7-7.noarch.rpm
然后就可以安装mysql-server
yum install mysql-server
开机启动mysql
systemctl enable mysqld.service
systemctl start mysqld.service
刚刚安装mysql是不知道初始密码的,所以需要获取初始密码
mysqld --initialize
grep 'temporary password' /var/log/mysqld.log
然后会给你一个密码
[Server] A temporary password is generated for root@localhost: t:-k9rLh(xXX
这样使用这个密码就可以登录mysql,然后修改我们自己的密码了
mysql -u root -p
登录进去后,进行操作,会提示我们修改密码
ERROR 1820 (HY000): You must reset your password using ALTER USER statement before executing this statement
修改密码
alter user user() identified by '你的密码';
二、连接mysql
安装完mysql之后,可能远程无法链接到你的服务器数据库
进入mysql
show databases;
use mysql;
update user set host='%' where user = 'root';
flush privileges;
select host, user from user;
+-----------+------------------+
| host | user |
+-----------+------------------+
| % | root |
| localhost | mysql.infoschema |
| localhost | mysql.session |
| localhost | mysql.sys |
+-----------+------------------+
这样就可链接服务器数据库了