ubuntu-mysql的安装

1.安装服务器

在终端中输入如下命令,回车后,然后按照提示输入

sudo apt-get install mysql-server

如果出如下的错误:

下列软件包有未满足的依赖关系:
 mysql-server : 依赖: mysql-server-5.7 但是它将不会被安装
E: 无法修正错误,因为您要求某些软件包保持现状,就是它们破坏了软件包间的依赖关系。

执行:

sudo apt-get update

上述命令执行完差不多是这个样子:

获取:76 http://cn.archive.ubuntu.com/ubuntu bionic-backports/universe i386 Packages [10.3 kB]
获取:77 http://cn.archive.ubuntu.com/ubuntu bionic-backports/universe Translation-en [4,588 B]
获取:78 http://cn.archive.ubuntu.com/ubuntu bionic-backports/universe amd64 DEP-11 Metadata [9,272 B]
获取:79 http://cn.archive.ubuntu.com/ubuntu bionic-backports/universe DEP-11 48x48 Icons [2,809 B]
获取:80 http://cn.archive.ubuntu.com/ubuntu bionic-backports/universe DEP-11 64x64 Icons [3,943 B]
已下载 57.4 MB,耗时 3分 27秒 (277 kB/s)                                       
正在读取软件包列表... 完成

再次执行:

sudo apt-get install mysql-server

这里又出错了,类似这样(截取末尾)

10月 02 20:18:05 wxl-virtual-machine systemd[1]: mysql.service: Service hold-off time over, scheduling restart.
10月 02 20:18:05 wxl-virtual-machine systemd[1]: mysql.service: Scheduled restart job, restart counter is at 2.
10月 02 20:18:05 wxl-virtual-machine systemd[1]: Stopped MySQL Community Server.
10月 02 20:18:05 wxl-virtual-machine systemd[1]: Starting MySQL Community Server...
dpkg: 处理软件包 mysql-server-5.7 (--configure)时出错:
 installed mysql-server-5.7 package post-installation script subprocess returned error exit status 1
dpkg: 依赖关系问题使得 mysql-server 的配置工作不能继续:
 mysql-server 依赖于 mysql-server-5.7;然而:
  软件包 mysql-server-5.7 尚未配置。

dpkg: 处理软件包 mysql-server (--configure)时出错:
 依赖关系问题 - 仍未被配置
正在处理用于 libc-bin (2.27-3ubuntu1) 的触发器 ...
因为错误消息指示这是由于上一个问题导致的错误,没有写入 apport 报告。
                                                                    正在处理用于 ureadahead (0.100.0-20) 的触发器 ...
正在处理用于 systemd (237-3ubuntu10.3) 的触发器 ...
在处理时有错误发生:
 mysql-server-5.7
 mysql-server


E: Sub-process /usr/bin/dpkg returned an error code (1)

别着急,在终端继续输入

sudo mv /var/lib/dpkg/info /var/lib/dpkg/info.bk

紧接着输入;

sudo mkdir /var/lib/dpkg/info

接着输入

sudo apt-get update

这里会出现一个结果,我只截取末尾的部分

获取:9 http://cn.archive.ubuntu.com/ubuntu bionic-updates/main DEP-11 48x48 Icons [80.2 kB]
获取:10 http://cn.archive.ubuntu.com/ubuntu bionic-updates/universe amd64 DEP-11 Metadata [299 kB]
获取:11 http://cn.archive.ubuntu.com/ubuntu bionic-updates/multiverse amd64 DEP-11 Metadata [2,468 B]
获取:12 http://cn.archive.ubuntu.com/ubuntu bionic-backports/universe amd64 DEP-11 Metadata [9,272 B]
已下载 1,046 kB,耗时 5秒 (214 kB/s)                                         
正在读取软件包列表... 完成

接着执行:

sudo apt-get install -f 

执行以下sudo语句,这里为了粘贴方便我就直接拷贝我的终端了,要一句一句执行:

w@w-virtual-machine:~$ sudo mv /var/lib/dpkg/info/* /var/lib/dpkg/info.bk
w@w-virtual-machine:~$ sudo rm -rf /var/lib/dpkg/info
w@w-virtual-machine:~$ sudo mv /var/lib/dpkg/info.bk /var/lib/dpkg/info
w@w-virtual-machine:~$ sudo apt-get install mysql-server
正在读取软件包列表... 完成

开启服务器:

 sudo service mysql start

查看

ps ajx|grep mysql

*关闭服务器的命令(这里不用执行,只是了解命令)

 sudo service mysql stop

查看服务器的配置

w@w-virtual-machine:~$ vi /etc/mysql/mysql.cnf
w@w-virtual-machine:~$ cd /etc/mysql/mysql.conf.d/
w@w-virtual-machine:/etc/mysql/mysql.conf.d$ ls
mysqld.cnf  mysqld_safe_syslog.cnf
w@w-virtual-machine:/etc/mysql/mysql.conf.d$ vi mysqld.cnf 

主要配置项如下
bind-address表示服务器绑定的ip,默认为127.0.0.1
port表示端口,默认为3306
datadir表示数据库目录,默认为/var/lib/mysql
general_log_file表示普通日志,默认为/var/log/mysql/mysql.log
log_error表示错误日志,默认为/var/log/mysql/error.log

2.客户端的安装

在终端运行如下命令,按提示填写信息

sudo apt-get install mysql-client

我这里报错了

E: 无法获得锁 /var/lib/dpkg/lock - open (11: 资源暂时不可用)
E: 无法锁定管理目录(/var/lib/dpkg/),是否有其他进程正占用它?

尝试输入mysql --help,也有出现这样一大堆的东西;

w@w-virtual-machine:~$ mysql --help
mysql  Ver 14.14 Distrib 5.7.35, for Linux (x86_64) using  EditLine wrapper
Copyright (c) 2000, 2021, Oracle and/or its affiliates.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

试试登录mysql把,(报错了-Can’t connect to local MySQL server through socket ‘/var/run/mysqld/mysqld.sock’)

w@w-virtual-machine:~$ mysql -u root -pmysql
mysql: [Warning] Using a password on the command line interface can be insecure.
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2)

*可能是服务器没开,执行以下开启命令(因为我期间有一步关了)

sudo service mysql start

好了,在执行一次

mysql -u root -pmysql

出现了一个这样的错误

mysql: [Warning] Using a password on the command line interface can be insecure.
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES)

搜了一下,继续执行
1.

 sudo /etc/init.d/mysql stop 
sudo mysqld_safe --skip-grant-tables &

ps.
(1)这里也报错了,UNIX socket file don’t exists

2021-10-03T03:05:17.959115Z mysqld_safe Logging to '/var/log/mysql/error.log'.
2021-10-03T03:05:18.008261Z mysqld_safe Directory '/var/run/mysqld' for UNIX socket file don't exists.

(2)就需要创建了,这里不用看我$前面的路径,直接sudo一条一条执行就可

w@w-virtual-machine:/etc/mysql/mysql.conf.d$ sudo mkdir -p /var/run/mysqld
w@w-virtual-machine:/etc/mysql/mysql.conf.d$ sudo chown mysql:mysql /var/run/mysqld
w@w-virtual-machine:/etc/mysql/mysql.conf.d$ sudo mysqld_safe --skip-grant-tables &

(3)出现这个就可以了

2021-10-03T03:11:13.041296Z mysqld_safe Logging to '/var/log/mysql/error.log'.
2021-10-03T03:11:13.196798Z mysqld_safe Starting mysqld daemon with databases from /var/lib/mysql

3.登录

mysql -u root mysql

修改MySQL登录密码和用户,这里我用户名是root,密码也一样root

mysql> update mysql.user set authentication_string=password('root') where user='root';

结果显示

Query OK, 1 row affected, 1 warning (0.00 sec)
Rows matched: 1  Changed: 1  Warnings: 1

提交commit,退出exit,一句一句执行

mysql> commit;
Query OK, 0 rows affected (0.00 sec)

mysql> exit;
Bye

好了,登录了

mysql -u root

这里我就能直接以root身份进行mysql了,到这里就结束了…





中间有很多错误没有说原因,大家可以自己看一下

链接:
错误1
.ERROR 1045 (28000): Access denied for user ‘melina’@‘localhost’ (using password: YES) 的处理方法
解决链接:http://blog.sina.com.cn/s/blog_6d802e7b0100qtnq.html(不全,需要几个一起看)
https://blog.51cto.com/sunrisenan/1884419

错误2:
解决mysqld_safe Directory ‘/var/run/mysqld’ for UNIX socket file don’t exists
解决链接:
https://blog.csdn.net/z_yttt/article/details/73650495

错误3
.网上有这样修改的mysql的用户和密码,出错
mysql> update user set password=password(“新密码”) where user=”用户名”;
执行后报错  ERROR 1054(42S22) Unknown column ‘password’ in ‘field list’
解决链接:
https://www.cnblogs.com/wangbaobao/p/7087032.html

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值