linux mysql deb 安装_linux安装mysql (rpm + yum + deb)

Mysql数据库的版本:mysql-5.7.26

方式一:rpm安装MySQL

一 安装前准备

1、检查是否已经安装过mysql,执行命令

[root@localhost /]# rpm -qa | grep mysql

d8d36d06a77787054b94d4bf0a8f5cb6.png

执行结果显示,有三个安装包,进行删除

[root@localhost ~]# yum remove mysql qt5-qtbase-mysql-5.9.2-3.el7.x86_64

3a8999b7d5e002dac6b16723d2671a94.png

如果出现上述类似结果(此为安装完成后的版本),可以看出我们已经安装了mysql-server-5.7.26-1.el7.x86_64, mysql-community-common-5.7.26-1.el7.x86_64

执行删除命令

[root@localhost /]# rpm -e --nodeps mysql-server-5.7.26-1.el7.x86_64

再次执行查询命令,查看是否删除

[root@localhost /]# rpm -qa | grep mysql

format,png

2、查询所有Mysql对应的文件夹

b37f614b20a5f45dac3b6673a7d036d4.png

删除相关目录或文件

[root@localhost /]# rm -rf /usr/lib64/mysql /usr/include/mysql /usr/share/mysql

验证是否删除完毕

3、检查mysql用户组和用户是否存在,如果没有,则创建

4、从官网下载是用于Linux的Mysql安装包

format,png

二 安装Mysql

1、在执行wget命令的目录下或你的上传目录下找到Mysql安装包:

ae97260de3ecc31d372c33353a092200.png

2、执行安装命令:

rpm -ivh mysql-community-common-5.7.26-1.el7.x86_64.rpm

rpm -ivh mysql-community-libs-5.7.26-1.el7.x86_64.rpm

rpm -ivh mysql-community-client-5.7.26-1.el7.x86_64.rpm

rpm -ivh mysql-community-server-5.7.26-1.el7.x86_64.rpm

rpm -ivh mysql80-community-release-el7-1.noarch.rpm

256b2dfcd1ba2d8e80e6352ecfa3e05f.png

出现如上错误,根据提示:1.要先安装mysql-community-common

2.依赖mariadb,需要删除mariadb (据说centos7 默认mariadb)

删除mariadb命令:rpm -e --nodeps mariadb-libs-5.5.41-2.el7_0.x86_64

c204c52ff56d7d449195403b071fb997.png

出现如上错误,需要在安装命令加上 :

--force --nodeps

3、安装完成后启动

systemctl start mysqld

4、查看初始密码

a: grep "password" /var/log/mysqld.log

b: cat /var/log/mysqld.log | grep password

ae393518199fa8226b927e0c68d06c86.png

5、使用初始密码登录mysql

mysql -uroot -pxEoLfqm6Nr-*

3b393e3c65d28da0734c7c68b2df06fe.png

注:此处可能会遇到密码错误,或者格式不对的等异常, 如果出现此问题导致不能登录mysql,使用下面方法:

关闭mysq服务:

systemctl stop mysqld

设置mysql不校验权限:

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

启动mysq服务:

systemctl start mysqld

登录mysql:

mysql -uroot

继续步骤6,在步骤7进入”注“步骤

6、设置密码

先执行刷新权限,否则可能报错:

flush privileges;

ALTER USER 'root'@'localhost' IDENTIFIED BY 'mysql@2020';

或者 ALTER USER 'root'@'%' IDENTIFIED BY 'mysql@2020';

7、退出mysql

quit

注:如果设置了步骤5中的不校验权限,需要进入如下操作

关闭mysq服务:

systemctl stop mysqld

设置mysql校验权限:

systemctl unset-environment MYSQLD_OPTS

启动mysq服务:

systemctl start mysqld

8、使用新密码登录

mysql -uroot -pmysql@2020

9、开放远程连接

10、设置开机自动启动

systemctl enable mysqld

11、mysql操作命令

方式二:yum安装MySQL

运行以下命令更新YUM源。

rpm -Uvh http://dev.mysql.com/get/mysql57-community-release-el7-9.noarch.rpm

8.0:

yum localinstall https://repo.mysql.com//mysql80-community-release-el7-1.noarch.rpm

运行以下命令安装MySQL。

yum -y install mysql-community-server

运行以下命令查看MySQL版本号。

mysql -V

返回结果如下,表示MySQL安装成功。

mysql Ver 14.14 Distrib 5.7.26, for Linux (x86_64) using EditLine wrapper

8.0.21版本 更改初始密码:

1.在 /etc/my.cnf 中的 [mysqld] 中添加 skip-grant-table

2.使用 [root]# server mysql restart 重启服务

3.输入 [root]# mysql 无密码登录到mysql中

4.使用 mysql > use mysql #选择数据库

5.使用 mysql > update user set authentication_string='' where user='root'; #将root的权限验证字符串更新为空

6.使用 mysql > select Host,User,authentication_string from user; #查询是否更新成功

7.使用 mysql > flush privileges #刷新权限

8.使用 mysql > exit #退出MySQL

9.在配置文件[root]# vim /etc/my.cnf 中注释 #skip-grant-table

10.重复第2步骤 重启服务

11.使用 [root]# mysql -uroot -p 后直接回车登录到MySQL中 【注意其他语句可能有兼容问题导致【Mysql8.0】ERROR 1820 (HY000): You must reset your password using ALTER USER statement】

12.使用 mysql > set password='your password'; #输入密码

13.重复第7步。

ALTER USER 'root'@'%' IDENTIFIED WITH mysql_native_password BY '新密码';

配置MySQL

运行以下命令启动MySQL服务。

systemctl start mysqld

运行以下命令设置MySQL服务开机自启动。

systemctl enable mysqld

运行以下命令查看/var/log/mysqld.log文件,获取并记录root用户的初始密码。

# grep 'temporary password' /var/log/mysqld.log

2019-04-28T06:50:56.674085Z 1 [Note] A temporary password is generated for root@localhost: 3w)WqGlM7-o,

说明 下一步对MySQL进行安全性配置时,会使用该初始密码。

运行下列命令对MySQL进行安全性配置。

mysql_secure_installation

重置root用户的密码。

Enter password for user root: #输入上一步获取的root用户初始密码

The 'validate_password' plugin is installed on the server.

The subsequent steps will run with the existing configuration of the plugin.

Using existing password for root.

Estimated strength of the password: 100

Change the password for root ? ((Press y|Y for Yes, any other key for No) : Y #是否更改root用户密码,输入Y

New password: #输入新密码,长度为8至30个字符,必须同时包含大小写英文字母、数字和特殊符号。特殊符号可以是()` ~!@#$%^&*-+=|{}[]:;‘<>,.?/

Re-enter new password: #再次输入新密码

Estimated strength of the password: 100

Do you wish to continue with the password provided?(Press y|Y for Yes, any other key for No) : Y #是否继续操作,输入Y

删除匿名用户账号。

By default, a MySQL installation has an anonymous user, allowing anyone to log into MySQL without having to have auser account created for them. This is intended only for testing, and to make the installation go a bit smoother. You should remove them before moving into a production environment.

Remove anonymous users? (Press y|Y for Yes, any other key for No) : Y #是否删除匿名用户,输入Y

Success.

禁止root账号远程登录。

Disallow root login remotely? (Press y|Y for Yes, any other key for No) : Y #禁止root远程登录,输入Y

Success.

删除test库以及对test库的访问权限。

Remove test database and access to it? (Press y|Y for Yes, any other key for No) : Y #是否删除test库和对它的访问权限,输入Y

- Dropping test database...

Success.

重新加载授权表。

Reload privilege tables now? (Press y|Y for Yes, any other key for No) : Y #是否重新加载授权表,输入Y

Success.

All done!

方式三:deepin(debian) deb安装MySQL

下载。

为了避免各种依赖无法下载,选择所有依赖包集合bundle:

mysql8.0的链接:mysql-server_8.0.22-1debian10_amd64.deb-bundle.tar

wget https://dev.mysql.com/get/Downloads/MySQL-8.0/mysql-server_8.0.22-1debian10_amd64.deb-bundle.tar

或者去MySQL官网下载对应版本,拷贝到服务器

解压。

解压.tar压缩包

tar -xvf mysql-server_8.0.22-1debian10_amd64.deb-bundle.tar

删除多余的test和debug包

rm *test*

安装。

安装依赖包

sudo apt-get install libmecab2 libjson-perl

安装所有mysql包

sudo dpkg -t mysql-*.deb

安装配置

安装过程中会弹出设置密码对话框,输入密码,确认密码。

5. 登录

mysql -uroot -p

输入密码进入数据库

卸载

查看MySQL的依赖项:

dpkg --list|grep mysql

将列出来的相关依赖依次移除

sudo apt-get remove mysql-common

sudo apt-get remove mysql-apt-config

删除mysql

sudo apt-get autoremove --purge mysql-8.0

dpkg -l|grep ^rc|awk '{print$2}'|sudo xargs dpkg -P清除残留数据

再次查看mysql依赖

dpkg --list|grep mysql

清除完毕

  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值