[software development] 统信UOS 安装二级制版MySQL8.4
Tofloor
poster avatar
李昊哲
deepin
2024-06-23 07:24
Author

统信UOS 安装二级制版MySQL8.4

建立MySQL用户和用户组

sudo groupadd mysql
sudo useradd -r -g mysql -s /bin/false mysql

下载MySQL安装包

wget https://cdn.mysql.com//Downloads/MySQL-8.4/mysql-8.4.0-linux-glibc2.28-x86_64.tar.xz

解压缩MySQL安装包

sudo tar -xvf mysql-8.4.0-linux-glibc2.28-x86_64.tar.xz

移动安装包到指定目录

sudo mv mysql-8.4.0-linux-glibc2.28-x86_64 /usr/local/mysql

创建链接符号目录

sudo mkdir /usr/local/mysql/mysql-files

修改目录所属

sudo chown -R mysql:mysql /usr/local/mysql

链接符号目录授权

sudo chmod 750 /usr/local/mysql/mysql-files

配置环境变量

临时环境变量

export PATH=$PATH:/usr/local/mysql/bin

永久环境变量

sudo vim /etc/profile

末尾追加以下内容

export PATH=$PATH:/usr/local/mysql/bin

初始化数据库

sudo /usr/local/mysql/bin/mysqld --initialize --user=mysql

注意:MySQL初始密码会打印在控制台上

例如:[Note] [MY-010454] [Server] A temporary password is generated for root@localhost: .mT/UTw%<5&=

image-20240622222828093.png

启动MySQL

sudo /usr/local/mysql/bin/mysqld_safe --user=mysql &

修改MySQL root用户密码和授权可访问主机

打开新的控制台执行以下命令

sudo /usr/local/mysql/bin/mysql -uroot -p

根据提示输入之前打印在控制台上的MySQL初始密码
注意:第一次输入可能是操作系统用户密码

image-20240622223309367.png

修改 root 用户密码为 lihaozhe

alter user 'root'@'localhost' IDENTIFIED BY 'lihaozhe';
flush privileges;

授权任意主机皆可访问

update mysql.user set host = '%' where user = 'root';
flush privileges;

退出MySQL

exit;

设置MySQL服务

在新的控制台执行以下命令

sudo cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysql.server

控制 MySQL 可以使用 以下命令

sudo service mysql.server start

sudo service mysql.server stop

sudo service mysql.server restart

sudo service mysql.server reloead

测试

重启操作系统

手动开启MySQL服务

sudo service mysql.server start 

登录MySQL

使用自定义密码登录

mysql -uroot -p

image-20240622223606415.png

Reply Favorite View the author
All Replies
hanzn-zzx
deepin
2024-06-23 08:20
#1

like

(虽然我不太用得上哈哈

Reply View the author
璀璨星空
deepin
2024-06-23 11:21
#2

环境变量那个是不是也适配用小皮面板之类工具安装的数据库confused

Reply View the author
乾豫恒益
deepin
2024-06-26 16:58
#3

实用,完整,收藏了。。。

Reply View the author
deepin
2024-07-03 16:41
#4

请教一下,如何设置开机自启mysql服务

Reply View the author
deepin
2024-07-03 16:46
#5
It has been deleted!
air2000
deepin
2024-09-16 22:55
#6
It has been deleted!
air2000
deepin
2024-09-16 23:04
#7

https://cdn.mysql.com//Downloads/MySQL-8.0/mysql-8.0.39-linux-glibc2.28-x86_64.tar.xz

Reply View the author