Deepin系统-安装与卸载mysql8.0.20

安装mysql

1.下载mysql-8.0.20

mysql最新版官方网站:https://dev.mysql.com/downloads/mysql/,目前已经更新到8.0.22

 

2.解压移动(注意不要修改解压到的地址),cd到~/Downloads(下载),输入以下代码

sudo tar -xvJf mysql-8.0.20-linux-glibc2.12-x86_64.tar.xz -C /usr/local

3.进入/usr/local目录

cd /usr/local

4.为mysql-8.0.20-linux-glibc2.12-x86_64目录创建软链接(方便操作)

sudo ln -s mysql-8.0.20-linux-glibc2.12-x86_64 mysql

5.添加mysql用户组和mysql用户(-s /bin/false参数指定mysql用户仅拥有所有权,而没有登录权限)

sudo groupadd mysql

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

如果有“mysql用户组和mysql用户”,安装会遇到报错,最好先用命令删除,详见“mysql用户组和mysql用户”删除命令。

6.进入安装mysql软件的目录

cd /usr/local/mysql

7.在/usr/local/mysql下建立data文件夹用于存放数据库文件

sudo mkdir /usr/local/mysql/data

 

(上面情况)如果创建data文件报错“mkdir: 无法创建目录 “/usr/local/mysql/data”: 文件已存在”,一定要用命令删除,见后面命令:

sudo rm -rf /usr/local/mysql/data

报错如下:(安装mysql时出现

2020-11-17T08:37:42.187488Z 0 [ERROR] [MY-010457] [Server] --initialize specified but the data directory has files in it. Aborting.

2020-11-17T08:37:42.187494Z 0 [ERROR] [MY-013236] [Server] The designated data directory /usr/local/mysql/data/ is unusable. You can remove all files that the server added to it.

2020-11-17T08:37:42.187543Z 0 [ERROR] [MY-010119] [Server] Aborting

删除完成之后,切记回来,重新运行命令sudo mkdir /usr/local/mysql/data。

8.修改当前目录拥有者为新建的mysql用户

sudo chown -R mysql:mysql ./

9.安装mysql

sudo ./bin/mysqld --user=mysql --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data --initialize

正常安装之后会显示如下结果:

2020-11-17T12:12:26.871935Z 0 [System] [MY-013169] [Server] /usr/local/mysql-8.0.20-linux-glibc2.12-x86_64/bin/mysqld (mysqld 8.0.20) initializing of server in progress as process 21656

2020-11-17T12:12:26.881497Z 1 [System] [MY-013576] [InnoDB] InnoDB initialization has started.

2020-11-17T12:12:27.765272Z 1 [System] [MY-013577] [InnoDB] InnoDB initialization has ended.

2020-11-17T12:12:29.081916Z 6 [Note] [MY-010454] [Server] A temporary password is generated for root@localhost: Sho)pu4AnA>J

记下随机产生的密码,我的是Sho)pu4AnA>J

Deepin可以用鼠标右键直接“复制”、“粘贴”,避免输错!(后面,root用户设置新密码,需要用到)

10.开启mysql服务

sudo ./support-files/mysql.server start

显示是这样的话就基本完成了

11.将mysql进程放入系统进程中

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

12.重新启动mysql服务

service mysqld restart

13.在/usr/bin下建立指向mysql的软连接之后使用随机密码登录mysql数据库

sudo ln -s /usr/local/mysql/bin/mysql /usr/bin

mysql -u root -p

根据提示输入第9步的随机密码

输入,回车(Enter)确定

Welcome to the MySQL monitor.  Commands end with ; or \g.

Your MySQL connection id is 8

Server version: 8.0.20

Copyright (c) 2000, 2020, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its

affiliates. Other names may be trademarks of their respective

owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql>

14.进入mysql操作行,为root用户设置新密码

alter user 'root'@'localhost' identified by '123456';

Query OK, 0 rows affected (0.02 sec)

此时,表示123456就已经是设置的新密码

好了mysql-8.0.20的安装到此结束,如果没有意外mysql-8.0.20已经安装到你的电脑里了

卸载mysql

如果卸载mysql需要,参考https://www.cnblogs.com/blogchen/articles/9074594.html

评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值