当先锋百科网

首页 1 2 3 4 5 6 7

Ubuntu16.04 安装 mysql 教程

安装命令

wct@ubuntu:~$ sudo apt-get install mysql-server
wct@ubuntu:~$ sudo apt-get install mysql-client

出现如下错误

2 not fully installed or removed.
Need to get 0 B/10.0 kB of archives.
After this operation, 111 kB of additional disk space will be used.
Selecting previously unselected package mysql-client.
(Reading database ... 220054 files and directories currently installed.)
Preparing to unpack .../mysql-client_5.7.30-0ubuntu0.16.04.1_all.deb ...
Unpacking mysql-client (5.7.30-0ubuntu0.16.04.1) ...
Setting up mysql-server-5.7 (5.7.30-0ubuntu0.16.04.1) ...
Renaming removed key_buffer and myisam-recover options (if present)
ERROR: Unable to start MySQL server:
mysqld: Can't read dir of '/etc/mysql/conf.d/' (Errcode: 2 - No such file or directory)
mysqld: [ERROR] Fatal error in defaults handling. Program aborted!
Please take a look at https://wiki.debian.org/Teams/MySQL/FAQ for tips on fixing common upgrade issues.
Once the problem is resolved, run apt-get --fix-broken install to retry.
dpkg: error processing package mysql-server-5.7 (--configure):
 subprocess installed post-installation script returned error exit status 1
No apport report written because the error message indicates its a followup error from a previous failure.
                          dpkg: dependency problems prevent configuration of mysql-server:
 mysql-server depends on mysql-server-5.7; however:
  Package mysql-server-5.7 is not configured yet.

dpkg: error processing package mysql-server (--configure):
 dependency problems - leaving unconfigured
Setting up mysql-client (5.7.30-0ubuntu0.16.04.1) ...
Errors were encountered while processing:
 mysql-server-5.7
 mysql-server
E: Sub-process /usr/bin/dpkg returned an error code (1)
hadoopwct@ubuntu:~$ sudo mysql_secure_installation
mysql_secure_installation: Can't read dir of '/etc/mysql/conf.d/' (Errcode: 2 - No such file or directory)
mysql_secure_installation: [ERROR] Fatal error in defaults handling. Program aborted!
hadoopwct@ubuntu:~$ mysql -u root -p
mysql: Can't read dir of '/etc/mysql/conf.d/' (Errcode: 2 - No such file or directory)
mysql: [ERROR] Fatal error in defaults handling. Program aborted!

这个错误差依赖,需要在 /etc/apt/sources.list 文件中像下面这样添加一行:deb http://cz.archive.ubuntu.com/ubuntu xenial-updates main连接
在这里插入图片描述
然后执行:sudo apt-get update 命令
在这里插入图片描述
执行安装命令发现还会出错,需要进行卸载mysql,如下命令:

wct@ubuntu:~$ sudo apt-get remove mysql-server mysql-client
wct@ubuntu:~$ sudo rm /var/lib/mysql/ -R
pwct@ubuntu:~$ sudo rm /etc/mysql/ -R
wct@ubuntu:~$ sudo apt-get autoremove mysql* --purge
pwct@ubuntu:~$ sudo apt-get remove apparmor

在进行安装,根据提示进行相应输入

wct@ubuntu:~$ sudo apt-get install mysql-server mysql-client

初始化MySQL安全脚本

wct@ubuntu:~$ sudo mysql_secure_installation

在这里插入图片描述
mysql_secure_installation会涉及是否修改root账号的密码、是否移除匿名用户、是否允许远程登录、是否删除test数据库等

可以正常使用了

在这里插入图片描述