再看亿遍 發表於 2021-6-24 23:34:00

ubuntu安装mysql

<h2><strong>卸载</strong></h2>
<div class="cnblogs_code">
<pre><span style="color: rgba(0, 0, 0, 1)">删除mysql的数据文件

sudo rm </span>/<span style="color: rgba(0, 0, 255, 1)">var</span>/lib/mysql/ -<span style="color: rgba(0, 0, 0, 1)">R


删除mysql的配置文件

sudo rm </span>/etc/mysql/ -<span style="color: rgba(0, 0, 0, 1)">R


自动卸载mysql(包括server和client)

sudo apt</span>-<span style="color: rgba(0, 0, 255, 1)">get</span> autoremove mysql* --<span style="color: rgba(0, 0, 0, 1)">purge

sudo apt</span>-<span style="color: rgba(0, 0, 255, 1)">get</span><span style="color: rgba(0, 0, 0, 1)"> remove apparmor


然后在终端中查看MySQL的依赖项:dpkg </span>--list|grep mysql</pre>
</div>
<h2>安装</h2>
<div class="cnblogs_code">
<pre><span style="color: rgba(0, 0, 0, 1)">sudo apt update
sudo apt install mysql</span>-server</pre>
</div>
<p>安装完成后,MySQL服务将自动启动。要验证MySQL服务器正在运行,请输入:</p>
<div class="cnblogs_code">
<pre>sudo systemctl status mysql</pre>
</div>
<p><img src="https://img2020.cnblogs.com/blog/1362551/202106/1362551-20210624225633612-1603957769.png"></p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<h2>&nbsp;安全操作</h2>
<p>输入root的密码,然后一系列的配置</p>
<div class="cnblogs_code">
<pre>root@VM-<span style="color: rgba(128, 0, 128, 1)">0</span>-<span style="color: rgba(128, 0, 128, 1)">2</span>-ubuntu:/etc/<span style="color: rgba(0, 0, 0, 1)">mysql# <strong>sudo mysql_secure_installation</strong>

Securing the MySQL server deployment.

Connecting to MySQL </span><span style="color: rgba(0, 0, 255, 1)">using</span><span style="color: rgba(0, 0, 0, 1)"> 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 </span><span style="color: rgba(0, 0, 255, 1)">set</span><span style="color: rgba(0, 0, 0, 1)"> only those passwords which are
secure enough. Would you like to setup VALIDATE PASSWORD plugin</span>?<span style="color: rgba(0, 0, 0, 1)">

Press y</span>|Y <span style="color: rgba(0, 0, 255, 1)">for</span> Yes, any other key <span style="color: rgba(0, 0, 255, 1)">for</span><span style="color: rgba(0, 0, 0, 1)"> No: <strong>y</strong>

There are three levels of password validation policy:

LOW    Length </span>&gt;= <span style="color: rgba(128, 0, 128, 1)">8</span><span style="color: rgba(0, 0, 0, 1)">
MEDIUM Length </span>&gt;= <span style="color: rgba(128, 0, 128, 1)">8</span>, numeric, mixed <span style="color: rgba(0, 0, 255, 1)">case</span><span style="color: rgba(0, 0, 0, 1)">, and special characters
STRONG Length </span>&gt;= <span style="color: rgba(128, 0, 128, 1)">8</span>, numeric, mixed <span style="color: rgba(0, 0, 255, 1)">case</span><span style="color: rgba(0, 0, 0, 1)">, special characters and dictionary                  file

Please enter </span><span style="color: rgba(128, 0, 128, 1)">0</span> = LOW, <span style="color: rgba(128, 0, 128, 1)">1</span> = MEDIUM and <span style="color: rgba(128, 0, 128, 1)">2</span> =<span style="color: rgba(0, 0, 0, 1)"> STRONG: root

Invalid option provided.

There are three levels of password validation policy:

LOW    Length </span>&gt;= <span style="color: rgba(128, 0, 128, 1)">8</span><span style="color: rgba(0, 0, 0, 1)">
MEDIUM Length </span>&gt;= <span style="color: rgba(128, 0, 128, 1)">8</span>, numeric, mixed <span style="color: rgba(0, 0, 255, 1)">case</span><span style="color: rgba(0, 0, 0, 1)">, and special characters
STRONG Length </span>&gt;= <span style="color: rgba(128, 0, 128, 1)">8</span>, numeric, mixed <span style="color: rgba(0, 0, 255, 1)">case</span><span style="color: rgba(0, 0, 0, 1)">, special characters and dictionary                  file

Please enter </span><span style="color: rgba(128, 0, 128, 1)">0</span> = LOW, <span style="color: rgba(128, 0, 128, 1)">1</span> = MEDIUM and <span style="color: rgba(128, 0, 128, 1)">2</span> = STRONG: <span style="color: rgba(128, 0, 128, 1)">12345678</span><span style="color: rgba(0, 0, 0, 1)">
Please </span><span style="color: rgba(0, 0, 255, 1)">set</span> the password <span style="color: rgba(0, 0, 255, 1)">for</span><span style="color: rgba(0, 0, 0, 1)"> root here.

New password:

Re</span>-enter <span style="color: rgba(0, 0, 255, 1)">new</span><span style="color: rgba(0, 0, 0, 1)"> password:

Estimated strength of the password: </span><span style="color: rgba(128, 0, 128, 1)">50</span><span style="color: rgba(0, 0, 0, 1)">
Do you wish to </span><span style="color: rgba(0, 0, 255, 1)">continue</span> with the password provided?(Press y|Y <span style="color: rgba(0, 0, 255, 1)">for</span> Yes, any other key <span style="color: rgba(0, 0, 255, 1)">for</span><span style="color: rgba(0, 0, 0, 1)"> No) : y
By </span><span style="color: rgba(0, 0, 255, 1)">default</span><span style="color: rgba(0, 0, 0, 1)">, a MySQL installation has an anonymous user,
allowing anyone to log into MySQL without having to have
a user account created </span><span style="color: rgba(0, 0, 255, 1)">for</span> them. This <span style="color: rgba(0, 0, 255, 1)">is</span> intended only <span style="color: rgba(0, 0, 255, 1)">for</span><span style="color: rgba(0, 0, 0, 1)">
testing, and to make the installation go a bit smoother.
You should remove them before moving into a production
environment.

Remove anonymous users</span>? (Press y|Y <span style="color: rgba(0, 0, 255, 1)">for</span> Yes, any other key <span style="color: rgba(0, 0, 255, 1)">for</span><span style="color: rgba(0, 0, 0, 1)"> No) : y
Success.


Normally, root should only be allowed to connect </span><span style="color: rgba(0, 0, 255, 1)">from</span>
<span style="color: rgba(128, 0, 0, 1)">'</span><span style="color: rgba(128, 0, 0, 1)">localhost</span><span style="color: rgba(128, 0, 0, 1)">'</span><span style="color: rgba(0, 0, 0, 1)">. This ensures that someone cannot guess at
the root password </span><span style="color: rgba(0, 0, 255, 1)">from</span><span style="color: rgba(0, 0, 0, 1)"> the network.

Disallow root login remotely</span>? (Press y|Y <span style="color: rgba(0, 0, 255, 1)">for</span> Yes, any other key <span style="color: rgba(0, 0, 255, 1)">for</span><span style="color: rgba(0, 0, 0, 1)"> No) : n

... skipping.
By </span><span style="color: rgba(0, 0, 255, 1)">default</span>, MySQL comes with a database named <span style="color: rgba(128, 0, 0, 1)">'</span><span style="color: rgba(128, 0, 0, 1)">test</span><span style="color: rgba(128, 0, 0, 1)">'</span><span style="color: rgba(0, 0, 0, 1)"> that
anyone can access. This </span><span style="color: rgba(0, 0, 255, 1)">is</span> also intended only <span style="color: rgba(0, 0, 255, 1)">for</span><span style="color: rgba(0, 0, 0, 1)"> testing,
and should be removed before moving into a production
environment.


Remove test database and access to it</span>? (Press y|Y <span style="color: rgba(0, 0, 255, 1)">for</span> Yes, any other key <span style="color: rgba(0, 0, 255, 1)">for</span><span style="color: rgba(0, 0, 0, 1)"> No) : y
</span>-<span style="color: rgba(0, 0, 0, 1)"> Dropping test database...
Success.

</span>-<span style="color: rgba(0, 0, 0, 1)"> 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</span>? (Press y|Y <span style="color: rgba(0, 0, 255, 1)">for</span> Yes, any other key <span style="color: rgba(0, 0, 255, 1)">for</span><span style="color: rgba(0, 0, 0, 1)"> No) : y
Success.

All done</span>!</pre>
</div>
<h2>登录</h2>
<div class="cnblogs_code">
<pre><span style="color: rgba(0, 0, 0, 1)">sudo mysql
或者
mysql </span>-u root -p</pre>
</div>
<p><img src="https://img2020.cnblogs.com/blog/1362551/202106/1362551-20210624230113861-200774204.png"></p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<h2>&nbsp;创建用户</h2>
<div class="cnblogs_code">
<pre><span style="color: rgba(0, 0, 0, 1)">命令:
CREATE USER ‘username’@’host’ IDENTIFIED BY ‘password’;
说明:
username:你将创建的用户名
host:指定该用户在哪个主机上可以登陆,如果是本地用户可用localhost,如果想让该用户可以从任意远程主机登陆,可以使用通配符</span>%<span style="color: rgba(0, 0, 0, 1)">
password:该用户的登陆密码,密码可以为空,如果为空则该用户可以不需要密码登陆服务器
例子:
CREATE USER ‘dog’@’localhost’ IDENTIFIED BY ‘</span><span style="color: rgba(128, 0, 128, 1)">123456</span><span style="color: rgba(0, 0, 0, 1)">’;
CREATE USER ‘pig’@’</span><span style="color: rgba(128, 0, 128, 1)">192.168</span>.<span style="color: rgba(128, 0, 128, 1)">1</span>.101_’ IDENDIFIED BY ‘<span style="color: rgba(128, 0, 128, 1)">123456</span><span style="color: rgba(0, 0, 0, 1)">’;
CREATE USER ‘pig’@’</span>%’ IDENTIFIED BY ‘<span style="color: rgba(128, 0, 128, 1)">123456</span><span style="color: rgba(0, 0, 0, 1)">’;
CREATE USER ‘pig’@’</span>%<span style="color: rgba(0, 0, 0, 1)">’ IDENTIFIED BY ”;
CREATE USER ‘pig’@’</span>%’;</pre>
</div>
<p>但是报错,因为上述代码的引号是中文字符,抄作业的后果</p>
<p><img src="https://img2020.cnblogs.com/blog/1362551/202106/1362551-20210624230215964-459930089.png"></p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<div class="cnblogs_code">
<pre><span style="color: rgba(0, 128, 0, 1)">//</span><span style="color: rgba(0, 128, 0, 1)"> 成功代码</span>
CREATE USER <span style="color: rgba(128, 0, 0, 1)">'</span><span style="color: rgba(128, 0, 0, 1)">dimp</span><span style="color: rgba(128, 0, 0, 1)">'</span>@<span style="color: rgba(128, 0, 0, 1)">'</span><span style="color: rgba(128, 0, 0, 1)">%</span><span style="color: rgba(128, 0, 0, 1)">'</span> IDENTIFIED BY <span style="color: rgba(128, 0, 0, 1)">'</span><span style="color: rgba(128, 0, 0, 1)">12345678</span><span style="color: rgba(128, 0, 0, 1)">'</span>;</pre>
</div>
<p>查看用户</p>
<div class="cnblogs_code">
<pre>SELECT User,Host FROM mysql.user;</pre>
</div>
<p>&nbsp;</p>
<p><img src="https://img2020.cnblogs.com/blog/1362551/202106/1362551-20210624232325425-384306947.png"></p>
<p>为用户授权</p>
<div class="cnblogs_code">
<pre><span style="color: rgba(0, 128, 0, 1)">//</span><span style="color: rgba(0, 128, 0, 1)">授予userone全部数据库权限,并修改密码</span>
grant all on *.* to <span style="color: rgba(128, 0, 0, 1)">'</span><span style="color: rgba(128, 0, 0, 1)">dimp</span><span style="color: rgba(128, 0, 0, 1)">'</span>@<span style="color: rgba(128, 0, 0, 1)">'</span><span style="color: rgba(128, 0, 0, 1)">%</span><span style="color: rgba(128, 0, 0, 1)">'</span> identified by <span style="color: rgba(128, 0, 0, 1)">'</span><span style="color: rgba(128, 0, 0, 1)">12345678</span><span style="color: rgba(128, 0, 0, 1)">'</span>;</pre>
</div>
<p>&nbsp;</p>
<h2>其他命令</h2>
<div class="cnblogs_code">
<pre><span style="color: rgba(0, 128, 0, 1)">//</span><span style="color: rgba(0, 128, 0, 1)"> 查看密码策略</span>
SHOW VARIABLES LIKE <span style="color: rgba(128, 0, 0, 1)">'</span><span style="color: rgba(128, 0, 0, 1)">validate_password%</span><span style="color: rgba(128, 0, 0, 1)">'</span>
<span style="color: rgba(0, 128, 0, 1)">//</span><span style="color: rgba(0, 128, 0, 1)"> 设置密码强度为low</span>
<span style="color: rgba(0, 0, 255, 1)">set</span> <span style="color: rgba(0, 0, 255, 1)">global</span> validate_password_policy=LOW;</pre>
</div>
<p>&nbsp;</p>
<div class="cnblogs_code">
<pre><span style="color: rgba(0, 0, 0, 1)">关于 mysql 密码策略相关参数;
</span><span style="color: rgba(128, 0, 128, 1)">1</span><span style="color: rgba(0, 0, 0, 1)">)validate_password_length &nbsp;固定密码的总长度;
</span><span style="color: rgba(128, 0, 128, 1)">2</span><span style="color: rgba(0, 0, 0, 1)">)validate_password_dictionary_file 指定密码验证的文件路径;
</span><span style="color: rgba(128, 0, 128, 1)">3</span>)validate_password_mixed_case_count &nbsp;整个密码中至少要包含大/<span style="color: rgba(0, 0, 0, 1)">小写字母的总个数;
</span><span style="color: rgba(128, 0, 128, 1)">4</span><span style="color: rgba(0, 0, 0, 1)">)validate_password_number_count &nbsp;整个密码中至少要包含阿拉伯数字的个数;
</span><span style="color: rgba(128, 0, 128, 1)">5</span><span style="color: rgba(0, 0, 0, 1)">)validate_password_policy 指定密码的强度验证等级,默认为 MEDIUM;
关于 validate_password_policy 的取值:
</span><span style="color: rgba(128, 0, 128, 1)">0</span>/<span style="color: rgba(0, 0, 0, 1)">LOW:只验证长度;
</span><span style="color: rgba(128, 0, 128, 1)">1</span>/<span style="color: rgba(0, 0, 0, 1)">MEDIUM:验证长度、数字、大小写、特殊字符;
</span><span style="color: rgba(128, 0, 128, 1)">2</span>/<span style="color: rgba(0, 0, 0, 1)">STRONG:验证长度、数字、大小写、特殊字符、字典文件;
</span><span style="color: rgba(128, 0, 128, 1)">6</span>)validate_password_special_char_count 整个密码中至少要包含特殊字符的个数</pre>
</div>
<p>&nbsp;</p>
<p><img src="https://img2020.cnblogs.com/blog/1362551/202106/1362551-20210624231112549-1126178078.png"></p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>查看端口</p>
<div class="cnblogs_code">
<pre>show <span style="color: rgba(0, 0, 255, 1)">global</span> variables like <span style="color: rgba(128, 0, 0, 1)">'</span><span style="color: rgba(128, 0, 0, 1)">port</span><span style="color: rgba(128, 0, 0, 1)">'</span>;</pre>
</div>
<p><img src="https://img2020.cnblogs.com/blog/1362551/202106/1362551-20210624233053038-1867199392.png"></p>
<p>&nbsp;</p>
<p>报错:sh: 0: getcwd() failed: No such file or directory</p>
<p>在执行命令前加 cd ~</p>
<p><img src="https://img2020.cnblogs.com/blog/1362551/202106/1362551-20210624233943193-1780056620.png"></p>
<p>&nbsp;</p><br><br>
来源:https://www.cnblogs.com/xiaojidanbai/p/14929103.html
頁: [1]
查看完整版本: ubuntu安装mysql