Ubuntu18.4 安装 MyServer 数据库

Ubuntu18.4 安装 MyServer 数据库 以及使用过程中踩到的坑

1.在安装 Ubuntu18.4 数据库的过程中踩了不少坑 , 最后参考此篇博客安装操作解决了问题

  • 首先安装 mysql

    在Ubuntu 18.04上,默认情况下,只有最新版本的 MySQL 包含在APT软件包存储库中。目前来说是MySQL 5.7。

    在安装之前需要更新服务器上的软件包索引然后才能使用apt安装默认软件包:

$ sudo apt update
$ sudo apt install mysql-server
  • 配置MySQL

$ sudo mysql_secure_installation

接下来将会通过一系列提示来对MySQL安装的安全选项进行一些更改(这一步非常重要):
首先便是要求设置root用户的密码:

Ubuntu18.4 安装 MyServer 数据库_第1张图片
在成功设置root密码之后还会有一系列的一些安全设置:

$ sudo mysql_secure_installation

Securing the MySQL server deployment.

Connecting to MySQL using a blank password.

VALIDATE PASSWORD PLUGIN can be used to test passwords
and improve security. It checks the strength of password
and allows the users to set only those passwords which are
secure enough. Would you like to setup VALIDATE PASSWORD plugin?

Press y|Y for Yes, any other key for No: Y

There are three levels of password validation policy:

LOW Length >= 8
MEDIUM Length >= 8, numeric, mixed case, and special characters
STRONG Length >= 8, numeric, mixed case, special characters and dictionary file

Please enter 0 = LOW, 1 = MEDIUM and 2 = STRONG: 0
Please set the password for root here.

New password:

Re-enter new password:

Estimated strength of the password: 50
Do you wish to continue with the password provided?(Press y|Y for Yes, any other key for No) : Y
By default, a MySQL installation has an anonymous user,
allowing anyone to log into MySQL without having to have
a user 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
Success.

Normally, root should only be allowed to connect from
‘localhost’. This ensures that someone cannot guess at
the root password from the network.

Disallow root login remotely? (Press y|Y for Yes, any other key for No) :

… skipping.
By default, MySQL comes with a database named ‘test’ that
anyone can access. This is also intended only for testing,
and should be removed before moving into a production
environment.

Remove test database and access to it? (Press y|Y for Yes, any other key for No) : Y

  • Dropping test database…
    Success.

  • Removing privileges on test database…
    Success.

Reloading the privilege tables will ensure that all changes
made so far will take effect immediately.

Reload privilege tables now? (Press y|Y for Yes, any other key for No) : Y
Success.

All done!

  • 验证mysql安装

    首先可以通过以下命令来查看mysql的运行状态:

   $ systemctl status mysql.service

显示结果如下即表示mysql正在运行

Ubuntu18.4 安装 MyServer 数据库_第2张图片

  • 登陆到mysql中

    使用root命令和刚才设置的密码来登陆到 mysql中去

   $ mysql -uroot -p

然后报了一处错误:

$ mysql -uroot -p
ERROR 1698 (28000): Access denied for user 'root'@'localhost'

我是借鉴了此篇博客
我先查询表,然后对表进行删除,最后添加表

也可以在这个命令前面加 sudo 执行,不过我编了一个Python程序,执行的时候报了一个这个错误
借鉴了此篇博客问题得到了解决

ERROR 1698 (28000): Access denied for user 'root'@'localhost'

最终完成了MyServer的安装,远程设置有需要的可以参考文章开始的那篇博客

2.此处是使用时遇到的坑 (运行自己项目的时候出现的一些错误,仅安装MySQL的可以忽略以下内容)

  • 在终端命令行中输入以下命令进入MySql
mysql -u root -p
  • 然后输入密码会得到一个如下界面
    Ubuntu18.4 安装 MyServer 数据库_第3张图片
    输入show databases; 会列出所有数据库,在MySQL中每个命令后面都要以 ; 结尾
    Ubuntu18.4 安装 MyServer 数据库_第4张图片
  • 选择使用的数据库,这里我用的是第二个 mysql 数据库
use mysql;

然后导入数据库文件

source path/file.sql  #path为文件真实路径

Ubuntu18.4 安装 MyServer 数据库_第5张图片

  • 然后另起一个终端,运行.py函数就可以了
    Ubuntu18.4 安装 MyServer 数据库_第6张图片
  • 数据库的增删改查可以参考此篇博客
  • 其中运行的时候报了一个 ImportError: cannot import name ‘nosetester’numpy版本不对
    用pip install 1.17.0的版本就可以解决,参考博客
pip install numpy==1.17.0

写的这些东西记录一下我踩得坑,以后再遇到方便查看

你可能感兴趣的:(Ubuntu,MyServer,数据库)