ubuntu18.04安装mysql及配置

解决docker启动MySQL:Can‘t create directory ‘/var/lib/mysql/‘ (Errcode: 17 - File exists) Errcode: 17 - File exists 阅读详情

A previous version of this tutorial was written by Hazel Virdó

Introduction

MySQL is an open-source database management system, commonly installed as part of the popular LAMP (Linux, Apache, MySQL, PHP/Python/Perl) stack. It uses a relational database and SQL (Structured Query Language) to manage its data.

The short version of the installation is simple: update your package index, install the mysql-server package, and then run the included security script.


 
  • sudo apt update
  • sudo apt install mysql-server
  • sudo mysql_secure_installation

This tutorial will explain how to install MySQL version 5.7 on an Ubuntu 18.04 server. However, if you're looking to update an existing MySQL installation to version 5.7, you can read this MySQL 5.7 update guide instead.

Prerequisites

To follow this tutorial, you will need:

Step 1 — Installing MySQL

On Ubuntu 18.04, only the latest version of MySQL is included in the APT package repository by default. At the time of writing, that's MySQL 5.7

To install it, update the package index on your server with apt:


 
  • sudo apt update

Then install the default package:


 
  • sudo apt install mysql-server

This will install MySQL, but will not prompt you to set a password or make any other configuration changes. Because this leaves your installation of MySQL insecure, we will address this next.

Step 2 — Configuring MySQL

For fresh installations, you'll want to run the included security script. This changes some of the less secure default options for things like remote root logins and sample users. On older versions of MySQL, you needed to initialize the data directory manually as well, but this is done automatically now.

Run the security script:


 
  • sudo mysql_secure_installation

This will take you through a series of prompts where you can make some changes to your MySQL installation’s security options. The first prompt will ask whether you’d like to set up the Validate Password Plugin, which can be used to test the strength of your MySQL password. Regardless of your choice, the next prompt will be to set a password for the MySQL root user. Enter and then confirm a secure password of your choice.

From there, you can press Y and then ENTER to accept the defaults for all the subsequent questions. This will remove some anonymous users and the test database, disable remote root logins, and load these new rules so that MySQL immediately respects the changes you have made.

To initialize the MySQL data directory, you would use mysql_install_db for versions before 5.7.6, and mysqld --initialize for 5.7.6 and later. However, if you installed MySQL from the Debian distribution, as described in Step 1, the data directory was initialized automatically; you don't have to do anything. If you try running the command anyway, you'll see the following error:

Output
mysqld: Can't create directory '/var/lib/mysql/' (Errcode: 17 - File exists)
. . .
2018-04-23T13:48:00.572066Z 0 [ERROR] Aborting

Note that even though you’ve set a password for the root MySQL user, this user is not configured to authenticate with a password when connecting to the MySQL shell. If you’d like, you can adjust this setting by following Step 3.

Step 3 — (Optional) Adjusting User Authentication and Privileges

In Ubuntu systems running MySQL 5.7 (and later versions), the root MySQL user is set to authenticate using the auth_socket plugin by default rather than with a password. This allows for some greater security and usability in many cases, but it can also complicate things when you need to allow an external program (e.g., phpMyAdmin) to access the user.

In order to use a password to connect to MySQL as root, you will need to switch its authentication method from auth_socket to mysql_native_password. To do this, open up the MySQL prompt from your terminal:


 
  • sudo mysql

Next, check which authentication method each of your MySQL user accounts use with the following command:


 
  • SELECT user,authentication_string,plugin,host FROM mysql.user;

 
Output
+------------------+-------------------------------------------+-----------------------+-----------+ | user | authentication_string | plugin | host | +------------------+-------------------------------------------+-----------------------+-----------+ | root | | auth_socket | localhost | | mysql.session | *THISISNOTAVALIDPASSWORDTHATCANBEUSEDHERE | mysql_native_password | localhost | | mysql.sys | *THISISNOTAVALIDPASSWORDTHATCANBEUSEDHERE | mysql_native_password | localhost | | debian-sys-maint | *CC744277A401A7D25BE1CA89AFF17BF607F876FF | mysql_native_password | localhost | +------------------+-------------------------------------------+-----------------------+-----------+ 4 rows in set (0.00 sec)

In this example, you can see that the root user does in fact authenticate using the auth_socket plugin. To configure the root account to authenticate with a password, run the following ALTER USER command. Be sure to change password to a strong password of your choosing, and note that this command will change the root password you set in Step 2:


 
  • ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'password';

Then, run FLUSH PRIVILEGES which tells the server to reload the grant tables and put your new changes into effect:


 
  • FLUSH PRIVILEGES;

Check the authentication methods employed by each of your users again to confirm that root no longer authenticates using the auth_socket plugin:


 
  • SELECT user,authentication_string,plugin,host FROM mysql.user;

 
Output
+------------------+-------------------------------------------+-----------------------+-----------+ | user | authentication_string | plugin | host | +------------------+-------------------------------------------+-----------------------+-----------+ | root | *3636DACC8616D997782ADD0839F92C1571D6D78F | mysql_native_password | localhost | | mysql.session | *THISISNOTAVALIDPASSWORDTHATCANBEUSEDHERE | mysql_native_password | localhost | | mysql.sys | *THISISNOTAVALIDPASSWORDTHATCANBEUSEDHERE | mysql_native_password | localhost | | debian-sys-maint | *CC744277A401A7D25BE1CA89AFF17BF607F876FF | mysql_native_password | localhost | +------------------+-------------------------------------------+-----------------------+-----------+ 4 rows in set (0.00 sec)

You can see in this example output that the root MySQL user now authenticates using a password. Once you confirm this on your own server, you can exit the MySQL shell:


 
  • exit

Alternatively, some may find that it better suits their workflow to connect to MySQL with a dedicated user. To create such a user, open up the MySQL shell once again:


 
  • sudo mysql

Note: If you have password authentication enabled for root, as described in the preceding paragraphs, you will need to use a different command to access the MySQL shell. The following will run your MySQL client with regular user privileges, and you will only gain administrator privileges within the database by authenticating:


 
  • mysql -u root -p

From there, create a new user and give it a strong password:


 
  • CREATE USER 'sammy'@'localhost' IDENTIFIED BY 'password';

Then, grant your new user the appropriate privileges. For example, you could grant the user privileges to all tables within the database, as well as the power to add, change, and remove user privileges, with this command:


 
  • GRANT ALL PRIVILEGES ON *.* TO 'sammy'@'localhost' WITH GRANT OPTION;

Note that, at this point, you do not need to run the FLUSH PRIVILEGES command again. This command is only needed when you modify the grant tables using statements like INSERT, UPDATE, or DELETE. Because you created a new user, instead of modifying an existing one, FLUSH PRIVILEGES is unnecessary here.

Following this, exit the MySQL shell:


 
  • exit

Finally, let's test the MySQL installation.

Step 4 — Testing MySQL

Regardless of how you installed it, MySQL should have started running automatically. To test this, check its status.


 
  • systemctl status mysql.service

You'll see output similar to the following:

Output
● mysql.service - MySQL Community Server
   Loaded: loaded (/lib/systemd/system/mysql.service; enabled; vendor preset: en
   Active: active (running) since Wed 2018-04-23 21:21:25 UTC; 30min ago
 Main PID: 3754 (mysqld)
    Tasks: 28
   Memory: 142.3M
      CPU: 1.994s
   CGroup: /system.slice/mysql.service
           └─3754 /usr/sbin/mysqld

If MySQL isn't running, you can start it with sudo systemctl start mysql.

For an additional check, you can try connecting to the database using the mysqladmin tool, which is a client that lets you run administrative commands. For example, this command says to connect to MySQL as root (-u root), prompt for a password (-p), and return the version.


 
  • sudo mysqladmin -p -u root version

You should see output similar to this:

Output
mysqladmin  Ver 8.42 Distrib 5.7.21, for Linux on x86_64
Copyright (c) 2000, 2018, 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.

Server version 5.7.21-1ubuntu1
Protocol version 10
Connection Localhost via UNIX socket
UNIX socket /var/run/mysqld/mysqld.sock
Uptime: 30 min 54 sec

Threads: 1 Questions: 12 Slow queries: 0 Opens: 115 Flush tables: 1 Open tables: 34 Queries per second avg: 0.006

This means MySQL is up and running.

Conclusion

You now have a basic MySQL setup installed on your server. Here are a few examples of next steps you can take:

mysqld 启动报错 Can‘t create directory ‘/usr/local/mysql/data/’(Errcode:2 -No such file or directory) mysqld 启动报错 Can‘t c 彻底解决办法 第一种 可以启动 但是其他配置其他参数没生效 ./mysqld --user=root --basedir=/usr/local/develop/mysql-5.7.31 --datadir=/usr/local/develop/mysql-5.7.31/data 第二种 指定配置文件其他配置其他参数生效 ./mysqld --defaults-file=/usr/local/develop/mysql-5.7.31/my.cnf --... 阅读详情

相关推荐

Ubuntu18.04系统安装并配置mysql

4、在 Windows 下可以使用 Navicat 图形化工具远程连接 Ubuntu 下的 MySQL 数据库,输入刚授权远程权限的密码。(3)随后删除匿名账户,并使用root管理员从远程登录数据库,以确保数据库上运行的业务的安全性。-u 表示选择登陆的用户名, -p 表示登陆的用户密码,新安装的mysql数据库是没有密码的,(期望安装,安装不完全,需要重装) 一般在安装过程中强行Ctrl-C就会出现这样的问题。表示:当安装包的时候会询问y/n,这个参数是所有询问默认y,直接下载安装,不再要求确认。

Roc的博客 6520

docker 启动数据库 mysqld: Can‘t create directory ‘/var/lib/mysql/‘ (Errcode: 17 - File exists)

使用docker启动数据库,然后发现容器启动失败,为什么呢? 查看容器日志 what?不能创建文件,文件已经存在 mysqld: Can't create directory '/var/lib/mysql/' (Errcode: 17 - File exists) ????什么鬼? 完全没有头绪,经过查阅一些资料,其实很简单,只需要加入权限参数--privileged=true 需要加,这个参数的作用是:使用该参数,container内的root拥有真正的root权限。否则,contai

wangxuelei036的博客 1万+

Linux:Ubuntu18.04安装及配置mysql connector C++

肯定可以使用的方法: 下载mysql connector的头文件和库:MySQL::Download Connector C++ 首先选择Linux-Generic,All下面的Linux - Generic (glibc 2.12) (x86, 64-bit), Compressed TAR Archive选项进行下载并安装;其次选择Ubuntu Linux,Ubuntu Linux 18....

不秃头的程序猿Gabriel的博客 2037

MySql安装错误:mysqld: Can't create directory

错误为无法创建目录 解决方法:   一:查看my.ini路径是否正确: 在设置数据的存放目录时,不需要单独添加Data文件夹,在写入路径的时候可以直接建立   二:查看安装路径是否存在中文:       路径正确,依旧报错,查看路径中是否含有中文,如果有中文在dos界面可以发现路径中的中文字为乱码,保证路径为中文即可。   三:地址斜杆使用错误:       这个是在查询此错误的时候其他博主写的...

番茄红了 5万+

Ubuntu 18.04 下MySQL数据库的安装、基本配置和完全卸载

ununtu下MySQL的安装 、基本配置 和完全卸载

ZY-JIMMY 1608

ubuntu18.04安装mysql5.7并配置数据存储路径

Ubuntu18.04安装Mysql5.7并配置存储路径

LDC,公众号【轻松学编程】 1564

/var/lib/mysql/is_writable_【已解决】Mac中mysqld去重新初始化mysql出错:mysqld Can’t create directory /usr/local/mys...

折腾:期间,尝试在Mac本地中去重新初始化mysql数据库,结果出错:➜AliyunRdsMysql mysqld --initializemysqld: Can't create directory '/usr/local/mysql-5.7.22-macos10.13-x86_64/data/' (Errcode: 17 - File exists)2018-04-27T02:28:43....

weixin_39756696的博客 733

SLAM算法的优缺点

SLAM(Simultaneous Localization and Mapping,同时定位与地图构建)算法是一种通过传感器数据实时估计机器人自身位置和构建环境地图的技术。

selenia8860的博客 2906

ubuntu18.04上安装配置MySQL的详细介绍

需求背景 在window10上安装配置mysql, 在windows上使用SQLyog连接到windows上的mysql 在虚拟上的ubuntu上安装配置mysql 在windows上使用SQLyog连接到ubuntu上的mysql 在云服务器上的CentOS上安装配置mysql并使用SQLyog连接 本篇文章主要介绍第二部分,在ubuntu18.04上安装配置MySQL 由于......

qq_36609501的博客 1万+

手把手教你用YOLOv11-seg-LSCD搞定树脂件瑕疵检测(附数据集与代码)

本文详细介绍了如何使用YOLOv11-seg-LSCD模型进行工业级树脂件瑕疵检测,包括环境配置、数据集构建、模型训练与调优、部署优化等全流程。通过LSCD模块的创新设计,有效提升了气泡、裂纹等微小缺陷的检测精度,适用于各类树脂制品的质量检测场景。

weixin_28677005的博客 418

微信小程序音视频通话(for硬件)授权与设备注册实战指南

本文详细介绍了微信小程序音视频通话(for硬件)组件的开发实践,涵盖授权流程、设备注册与VoIP插件集成。重点解析了如何通过服务端获取snTicket实现用户授权,确保硬件设备与微信端的音视频通话安全可靠,适用于智能门禁、话机等物联网场景。

u6v7w8x的博客 945

Ubuntu18.04下MySQL5.7安装配置

Ubuntu18.04中安装MySQL5.7 1.安装 直接通过源安装 sudo apt-get update sudo apt-get install mysql-server mysql-client sudo apt-get install libmysqlclient-dev 整个过程自动下载和安装,完成后,检查是否已正确安装并成功启动: sudo netstat -atp | ...

蜗牛、Gray 558

音视频入门:H264、H265概念总结

添加链接描述 什么是H.264与H.265 H.264与H.265都是视频压缩格式,由于视频本身的码流太大,所以需要经过压缩然后再通过网络进行传输。H.264是目前比较主流的压缩算法,像视频会议设备一般都采用这个编码格式。基础的H.264可以支持在1M带宽下传输720P30帧/秒的图像;H.264 HIGH PROFILE支持在512K带宽下传输720P30帧/秒的图像。 H.265是比较新的压缩算法,可以更一步提高压缩比,随着我们现在生活中出现的视频格式越来越大(比如现在基本都是1080P甚至4K的显示器

weixin_40673765的博客 8936

记一次ubuntu18.04 MySQL环境安装及配置

记一次ubuntu18.04 MySQL环境安装及配置安装MySQL配置MySQL 本文章主要参考以下博文:1、 Ubuntu18.04 安装MySQL 2、Ubuntu18.04(linux)安装MySQL 卸载MySQL请参考博文:Ubuntu18.04彻底删除MySQL数据库 谢谢原创作者的贡献! 安装MySQL 安装过程请参考以上博文,哈哈。。这里就偷懒不写啦,前人已总结的...

weixin_43323106的博客 1120

【01、Go与VSCode的安装】

小白学Go语言

wangruil的博客 1536

GPU硬件架构与微架构深度解析28-稀疏计算:稀疏矩阵计算的硬件支持

本文介绍了GPU加速稀疏计算的关键技术。主要内容包括:1)稀疏数据的存储格式(COO、CSR、CSC)及其特点;2)现代GPU的稀疏计算硬件优化,如NVIDIA的稀疏张量核心和内存访问优化;3)稀疏计算在推荐系统、NLP和科学计算等领域的应用案例;4)性能优化技巧,包括存储格式选择、硬件特性利用和混合精度计算等。文章指出,专用稀疏计算技术可显著提升AI和大规模科学计算的效率,相比传统方法可获得5-10倍的性能提升。

2301_79143213的博客 111

ubuntu18.04配置mysql_ubuntu18.04中mysql的安装及远程连接配置

1.ubuntu 18.04 下mysql的安装sudo apt install mysql-server2.mysql 安装配置sudo mysql_secure_installation参考配置#1VALIDATE PASSWORD PLUGIN can be used to test passwords...Press y|Y for Yes, any other key for No: N...

weixin_29550949的博客 142

SAP 批次管理

批次管理: 业务场景: 批次常用于:采购、生产、SD等: 1、先进先出,先入库的先出库(如何实现),基于入库时间来自动确定出库策略。 2、追塑:基于批次进行产品质量追溯 例如订单MTO ---> PP ----> MM(批次关联)。SO—>PP工单 --> 预留 --> 发料(基于批次A\B\C)-->产成品入库-->批次入库D--> ...

willieyuan的博客 1万+

Ubuntu18.04 安装MySQL及配置

版权声明:本文为博主原创文章,欢迎转载。 https://blog.csdn.net/weixx3/article/details/80782479 </div> <link rel="stylesheet" href="https://csd...

Jack Lee's blogs 327

第十二章 供水管网水力模型软件介绍

本文介绍了国内外主要供水管网建模软件及其特点,重点分析了某高建模软件V14的创新功能。国际主流软件包括开源的EPANET、商业软件InfoWorksWS、WaterGEMS和MIKEURBAN,各具特色但存在应用局限。某高V14软件实现了管网GIS与模型一体化管理,采用一G多网、一网多模、一模多案、网模合一技术路线,支持全信息模型建立和动态数据更新。其创新点包括水量分配理念革新(精确/模糊匹配、三种用水模式)和首创Web服务功能。通过并发计算、GPU加速等技术优化性能,具有较高性价比。

weixin_45258875的博客 207

汉书HE8,好用的汇编代码编写工具

汉书HE8,好用的汇编代码编写工具早期编写汇编代码所用功能强大

Ubuntu 18.04安装配置MySQL数据库

但是,通过第三方程序是无法连接到数据库的,例如JDBC、pymysql等。这里可以通过包管理工具apt安装MySQL数据库,在ubuntu18.04下mysql版本默认为5.7。说明已经可以通过Navicat成功连接MySQL数据库。此时,mysql客户端已经作为服务器的依赖安装到本地,故可以通过命令行登录服务器。找到 bind-address 配置,在前面加上 # 注释掉,然后保存文件。不管修改了什么配置,都需要重启服务,否则配置都不会生效。这时候再查看mysql状态,就能发现,监听地址变成了 [::]

酒酿小圆子呀~ 2405

Probability and Statistics - 4th edition

Probability and Statistics - 4th edition

docker容器ubuntu:18.04镜像安装mysql以及一些配置

pymysql.err.OperationalError: (1045, "Access denied for user 'user02'@'192.168.64.208' (using password: YES)") 一、具体ubuntu下使用mysql流程参考如下: pymysql在Ubuntu下的安装和使用_JSon liu的博客-优快云博客 二、提示以上错误时,基本上是权限问题导致的,故此修改权限如下: 1、mysql -u root -p (root用户密码登...

4520

C# WinForm 基于DirectShow.dll编写的程序,可边预览边保存视频,音频和图片

基于微软的DirectShow.dll的二次开发1.自动识别连接的摄像头跟麦克风且可以对其进行选择(默认选中第一个)2.可录制wmv和avi两种格式的视频并且都带有音频,avi可以录制的分辨率和帧数进行选择,wmv默认进行了淸晰度优化如不喜欢可去除代码中有相关提示3.可在预览点开之后进行拍照,也可边录制视频边拍照4.添加了视频和音频的压缩功能(酌情使用)这次二次开发发现C#对DirectShow的相关信息太少,这次做完也不敢藏私共享出来,还望大家指正

Devexpress16.2.6破解工具

Devexpress16.2.6破解工具Devexpress16.2.6破解工具Devexpress16.2.6破解工具Devexpress16.2.6破解工具

ubuntu mysql 安全设置_Ubuntu 18.04 安装和配置Mysql

1. 安装提示:以下操作均在root权限下进行。# 查看有没有安装MySQL:dpkg -l | grep mysql# 安装MySQL:apt install mysql-server安装完成之后可以使用如下命令来检查是否安装成功:netstat -tap | grep mysql通过上述命令检查之后,如果看到有 mysql 的socket处于 LISTEN 状态则表示安装成功。2. 配置roo...

weixin_28782251的博客 323

腾讯云Ubuntu18.04安装MySQL5.73,并配置SSL

随笔时间:2022-04-04 随笔内容:在Ubuntu中安装MySQL,配置SSL 服务器环境:腾讯云,Ubuntu18.04,MySQL5.7.3 啰嗦几句:一个半吊子程序员,已是为人父母年纪,难得有点时间能学习一点,可惜记忆大不如从前,本着有一点记一点的想法,记录下自己的使用经过,方便以后查看,东西可能比较简单,各位大神不喜勿喷,嘴下留情,谢谢。 背景介绍:腾讯云Ubuntu18.04安装MySQL5.73,配置SSL,提高数据库稳定性。 笔者自嘲:看了太多的网上的介绍,年代不一样,版本不一

wyxmybb的博客 827

ubuntu18.04安装mysql5.7.25与配置

ubuntu18.04安装mysql5.7.25与配置1 安装mysql2 配置2.1 配置root密码2.2 配置字符集 1 安装mysql sudo apt install mysql-server sudo apt install mysql-client sudo apt install libmysqlclient-dev 安装过程中是没有提示输入密码的,所以安装完成之后还要自己配置密...

qq_38627802的博客 1412

在ubuntu server 18.04上安装配置MySQL8.0手记

1、在ubuntu server 18.04上安装配置MySQL8.0     直接使用apt install mysql-server安装,那么恭喜你踩坑。sudo apt install mysql-server默认会安装MySQL 5.7,将会出现一些莫名的问题,例如:安装过程没有要求输入root密码,而登录mysql时会要求密码等等……     阅读了一下MySQL安装指南,发现M...

NOC00的专栏 956
上一篇: mysql安装与卸载
下一篇: ubuntu 18.04 sudo apt update 问题
SimpleForest
博客等级 码龄10年 171粉丝 95原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值