Linux服务器安装MySQL数据库

首先yum安装的版本比较低,所以先下载一个yum比较新的库文件
点击就是下载到本地,如果想在Linux里面下载就需要右击复制链接

在这里插入图片描述

1. 安装MySQL:

sudo apt update
sudo apt install mysql-server

2. 可以通过sudo systemctl status mysql命令查看MySQL是否已启动
3. 设置登录密码

root@***-virtual-machine:/etc/network# sudo mysql_secure_installation

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: 1
Please set the password for root here.
  • 根据提示输入要设置的密码即可!
  • 接着会删除测试数据库并重置相关数据表,一直输Y即可!

4. Failed! Error: SET PASSWORD has no significance for user ‘root‘@‘localhost‘ as the authe…问题解决

  • 部分安装过程中会遇到上述问题,原因是刚开始设置的密码太简单
  • 先通过sudo mysql命令进入mysql
  • 在命令行中执行以下命令
#因为上面在密码策略处选择的1,所以默认的密码检查机制为特殊符号+大小写+数字
ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password by '新密码';

mysql> SHOW VARIABLES LIKE 'validate_password%';
+--------------------------------------+--------+
| Variable_name                        | Value  |
+--------------------------------------+--------+
| validate_password.check_user_name    | ON     |
| validate_password.dictionary_file    |        |
| validate_password.length             | 8      |
| validate_password.mixed_case_count   | 1      |
| validate_password.number_count       | 1      |
| validate_password.policy             | MEDIUM |
| validate_password.special_char_count | 1      |
+--------------------------------------+--------+
7 rows in set (0.00 sec)

关于 mysql 密码策略相关参数;
1)、validate_password_length 固定密码的总长度;
2)、validate_password_dictionary_file 指定密码验证的文件路径;
3)、validate_password_mixed_case_count 整个密码中至少要包含大/小写字母的总个数;
4)、validate_password_number_count 整个密码中至少要包含阿拉伯数字的个数;
5)、validate_password_policy 指定密码的强度验证等级,默认为 MEDIUM;
关于 validate_password_policy 的取值:
0/LOW:只验证长度;
1/MEDIUM:验证长度、数字、大小写、特殊字符;
2/STRONG:验证长度、数字、大小写、特殊字符、字典文件;
6)、validate_password_special_char_count 整个密码中至少要包含特殊字符的个数;

  • 然后输入quitexit退出mysql回到终端命令行,输入:
sudo mysql_secure_installation

输入刚才的密码即可,出现的问题都选n.

root@***-virtual-machine:/home/***# `sudo mysql_secure_installation`

Securing the MySQL server deployment.

Enter password for user root: 
The 'validate_password' component is installed on the server.
The subsequent steps will run with the existing configuration
of the component.
Using existing password for root.

Estimated strength of the password: 100 
Change the password for root ? ((Press y|Y for Yes, any other key for No) : `n`

 ... skipping.
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) : `n`

 ... skipping.


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) : `n`

 ... 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) : `n`

 ... skipping.
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) :` n`

 ... skipping.
All done! 

5. 登录:

  • sudo mysql
  • mysql -u root -p

6. 将sql语句的文件解压:

unzip -d /opt/init_sql init_sql.zip 

7. 执行SQL

#进入sql
mysql -u root -p
#创建数据库
mysql> create database community;
Query OK, 1 row affected (0.01 sec)
#选中数据库
mysql> use community
Database changed
#导入数据
mysql> source /opt/init_sql/init_schema.sql;
......
mysql> source /opt/init_sql/init_data.sql;
......
mysql> source /opt/init_sql/tables_mysql_innodb.sql;
......
#导入后查看表
mysql> show tables;
+--------------------------+
| Tables_in_community      |
+--------------------------+
| QRTZ_BLOB_TRIGGERS       |
| QRTZ_CALENDARS           |
| QRTZ_CRON_TRIGGERS       |
| QRTZ_FIRED_TRIGGERS      |
| QRTZ_JOB_DETAILS         |
| QRTZ_LOCKS               |
| QRTZ_PAUSED_TRIGGER_GRPS |
| QRTZ_SCHEDULER_STATE     |
| QRTZ_SIMPLE_TRIGGERS     |
| QRTZ_SIMPROP_TRIGGERS    |
| QRTZ_TRIGGERS            |
| comment                  |
| discuss_post             |
| login_ticket             |
| message                  |
| user                     |
+--------------------------+
16 rows in set (0.00 sec)
#接下来修改user表,因为用户表的头像地址使用的还是http://localhost..
mysql> update user set header_url = 'http://images.nowcoder.com/head/666t.png' where header_url like '%localhost%';
#搞定退出
mysql> exit
Bye
root@***-virtual-machine:/opt# 
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值