ubuntu 安装 mysql

参考 How To Install MySQL on Ubuntu 20.04

1. 安装

# 查看 mysql-server 版本
 apt list mysql-server
# 安装, 建议安装之前,修改一下镜像,采用 淘宝镜像
 sudo apt install mysql-server

安装日志如下

⋊> /m/c/U/f/shells apt list mysql-server -a                                                                     10:19:48Listing... Done
mysql-server/focal-updates,focal-security 8.0.26-0ubuntu0.20.04.2 all
mysql-server/focal 8.0.19-0ubuntu5 all
mysql-server/bionic-security,bionic-updates 5.7.35-0ubuntu0.18.04.1 all
mysql-server/bionic 5.7.21-1ubuntu1 all

⋊> /m/c/U/f/shells sudo apt install mysql-server                                                                10:20:01[sudo] password for feijinping:
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following additional packages will be installed:
  libcgi-fast-perl libcgi-pm-perl libevent-core-2.1-7 libevent-pthreads-2.1-7 libfcgi-perl libhtml-template-perl
  libmecab2 mecab-ipadic mecab-ipadic-utf8 mecab-utils mysql-client-8.0 mysql-client-core-8.0 mysql-common
  mysql-server-8.0 mysql-server-core-8.0
Suggested packages:
  libipc-sharedcache-perl mailx tinyca
emitting double-array: 100% |###########################################|
reading /usr/share/mecab/dic/ipadic/matrix.def ... 1316x1316
emitting matrix      : 100% |###########################################|

done!
update-alternatives: using /var/lib/mecab/dic/ipadic-utf8 to provide /var/lib/mecab/dic/debian (mecab-dictionary) in auto mode
Setting up mysql-server-8.0 (8.0.26-0ubuntu0.20.04.2) ...
invoke-rc.d: could not determine current runlevel
 * Stopping MySQL database server mysqld                                                                         [ OK ]
update-alternatives: using /etc/mysql/mysql.cnf to provide /etc/mysql/my.cnf (my.cnf) in auto mode
Renaming removed key_buffer and myisam-recover options (if present)
Cannot open /proc/net/unix: No such file or directory
Cannot stat file /proc/1/fd/5: Operation not permitted
Cannot stat file /proc/1/fd/10: Operation not permitted
Cannot stat file /proc/1/fd/6: Operation not permitted
Cannot stat file /proc/7/fd/7: Operation not permitted
Cannot stat file /proc/7/fd/10: Operation not permitted
Cannot stat file /proc/7/fd/5: Operation not permitted
mysqld will log errors to /var/log/mysql/error.log
mysqld is running as pid 761
Created symlink /etc/systemd/system/multi-user.target.wants/mysql.service → /lib/systemd/system/mysql.service.
invoke-rc.d: could not determine current runlevel
Setting up mysql-server (8.0.26-0ubuntu0.20.04.2) ...
Processing triggers for systemd (245.4-4ubuntu3.11) ...
Processing triggers for man-db (2.9.1-1) ...
Processing triggers for libc-bin (2.31-0ubuntu9.2) ...

2. 配置

 sudo mysql_secure_installation                                                                                                                                                        

设置日志

10:43:59
Securing the MySQL server deployment.

Connecting to MySQL using a blank password.

VALIDATE PASSWORD COMPONENT 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 component?

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: 2
Please set the password for root here.

New password:

Re-enter new password:

Estimated strength of the password: 100
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) : y
Success.

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!

3. 创建管理用户并授权

sudo mysql

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 plugin requires that the name of the operating system user that invokes the MySQL client matches the name of the MySQL user specified in the command, so you must invoke mysql with sudo privileges to gain access to the root MySQL user:
在运行 MySQL 5.7(及更高版本)的 Ubuntu 系统中,root 用户默认设置为使用 auth_socket 插件而不是密码进行身份验证。该插件要求调用 MySQL 客户端的操作系统用户名与命令中指定的 MySQL 用户名匹配,因此必须以 sudo 权限调用 mysql 才能访问 MySQL 根用户
注意:如果您使用其他教程安装 MySQL 并为 root 启用密码身份验证,则需要使用不同的命令来访问 MySQL shell。下面将以常规用户权限运行您的 MySQL 客户端,并且您只能通过身份验证在数据库中获得管理员权限:

mysql -u root -p
# 创建用户
CREATE USER 'fjp'@'%' IDENTIFIED BY 'password';
# 赋予权限, 建议不要赋予全部权限
GRANT CREATE, ALTER, DROP, INSERT, UPDATE, DELETE, SELECT, REFERENCES, RELOAD on *.* TO 'fjp'@'%' WITH GRANT OPTION;
# flush 权限

注:建议看英文原文 https://www.digitalocean.com/community/tutorials/how-to-install-mysql-on-ubuntu-20-04

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值