首先我们需要在 Linux 操作系统里安装 MySQL 的服务:
输入命令: apt-get install MySQL-server MySQL-client
root@qiaowei-PC:/# apt-get install MySQL-server MySQL-client
正在读取软件包列表... 完成
正在分析软件包的依赖关系树
正在读取状态信息... 完成
将会同时安装下列软件:
- libcgi-fast-perl libcgi-pm-perl libevent-core-2.1-6 libfcgi-perl
- libhtml-template-perl libmecab2 MySQL-client-5.7 MySQL-client-core-5.7
- MySQL-common MySQL-server-5.7 MySQL-server-core-5.7
建议安装:
libipc-sharedcache-perl mailx tinyca
下列 [新] 软件包将被安装:
- libcgi-fast-perl libcgi-pm-perl libevent-core-2.1-6 libfcgi-perl
- libhtml-template-perl libmecab2 MySQL-client MySQL-client-5.7
- MySQL-client-core-5.7 MySQL-common MySQL-server MySQL-server-5.7
- MySQL-server-core-5.7
升级了 0 个软件包, 新安装了 13 个软件包, 要卸载 0 个软件包, 有 0 个软件包未被升级.
需要下载 0 B/21.7 MB 的归档.
解压缩后会消耗 163 MB 的额外空间.
您希望继续执行吗? [Y/n] y
正在预设定软件包 ...
正在选中未选择的软件包 MySQL-common.
(正在读取数据库 ... 系统当前共安装有 187699 个文件和目录.)
正准备解包 .../0-MySQL-common_5.8+1.0.4_all.deb ...
正在解包 MySQL-common (5.8+1.0.4) ...
正在选中未选择的软件包 MySQL-client-core-5.7.
正准备解包 .../1-MySQL-client-core-5.7_5.7.21-1_amd64.deb ...
正在解包 MySQL-client-core-5.7 (5.7.21-1) ...
正在选中未选择的软件包 MySQL-client-5.7.
正准备解包 .../2-MySQL-client-5.7_5.7.21-1_amd64.deb ...
正在解包 MySQL-client-5.7 (5.7.21-1) ...
正在选中未选择的软件包 MySQL-server-core-5.7.
正准备解包 .../3-MySQL-server-core-5.7_5.7.21-1_amd64.deb ...
正在解包 MySQL-server-core-5.7 (5.7.21-1) ...
正在选中未选择的软件包 libevent-core-2.1-6:amd64.
正准备解包 .../4-libevent-core-2.1-6_2.1.8-stable-4_amd64.deb ...
正在解包 libevent-core-2.1-6:amd64 (2.1.8-stable-4) ...
正在选中未选择的软件包 libmecab2:amd64.
正准备解包 .../5-libmecab2_0.996-6_amd64.deb ...
正在解包 libmecab2:amd64 (0.996-6) ...
正在设置 MySQL-common (5.8+1.0.4) ...
update-alternatives: 使用 /etc/MySQL/my.cnf.fallback 来在自动模式中提供 /etc/MySQL/my.cnf (my.cnf)
正在选中未选择的软件包 MySQL-server-5.7.
(正在读取数据库 ... 系统当前共安装有 187870 个文件和目录.)
正准备解包 .../0-MySQL-server-5.7_5.7.21-1_amd64.deb ...
正在解包 MySQL-server-5.7 (5.7.21-1) ...
正在选中未选择的软件包 libcgi-pm-perl.
正准备解包 .../1-libcgi-pm-perl_4.38-1_all.deb ...
正在解包 libcgi-pm-perl (4.38-1) ...
正在选中未选择的软件包 libfcgi-perl.
正准备解包 .../2-libfcgi-perl_0.78-2+b2_amd64.deb ...
正在解包 libfcgi-perl (0.78-2+b2) ...
正在选中未选择的软件包 libcgi-fast-perl.
正准备解包 .../3-libcgi-fast-perl_1:2.13-1_all.deb ...
正在解包 libcgi-fast-perl (1:2.13-1) ...
正在选中未选择的软件包 libhtml-template-perl.
正准备解包 .../4-libhtml-template-perl_2.97-1_all.deb ...
正在解包 libhtml-template-perl (2.97-1) ...
正在选中未选择的软件包 MySQL-client.
正准备解包 .../5-MySQL-client_5.7.21-1_all.deb ...
正在解包 MySQL-client (5.7.21-1) ...
正在选中未选择的软件包 MySQL-server.
正准备解包 .../6-MySQL-server_5.7.21-1_all.deb ...
正在解包 MySQL-server (5.7.21-1) ...
正在设置 libevent-core-2.1-6:amd64 (2.1.8-stable-4) ...
正在设置 MySQL-server-core-5.7 (5.7.21-1) ...
正在设置 libmecab2:amd64 (0.996-6) ...
正在处理用于 libc-bin (2.27-3) 的触发器 ...
正在处理用于 systemd (238-5) 的触发器 ...
正在设置 libcgi-pm-perl (4.38-1) ...
正在处理用于 man-db (2.8.3-2) 的触发器 ...
正在设置 MySQL-client-core-5.7 (5.7.21-1) ...
正在设置 libfcgi-perl (0.78-2+b2) ...
正在设置 libhtml-template-perl (2.97-1) ...
正在设置 libcgi-fast-perl (1:2.13-1) ...
正在设置 MySQL-client-5.7 (5.7.21-1) ...
正在设置 MySQL-client (5.7.21-1) ...
正在设置 MySQL-server-5.7 (5.7.21-1) ...
update-alternatives: 使用 /etc/MySQL/MySQL.cnf 来在自动模式中提供 /etc/MySQL/my.cnf (my.cnf)
- Renaming removed key_buffer and myisam-recover options (if present)
- 123456
- 123456
- Created symlink /etc/systemd/system/multi-user.target.wants/MySQL.service → /lib/systemd/system/MySQL.service.
正在设置 MySQL-server (5.7.21-1) ...
正在处理用于 systemd (238-5) 的触发器 ...
这样的会就表示我们安装完成了!
那么接下来就可以输入: MySQL
注意: 由于我们默认的时候 MySQL 在 deepin 的环境下是没有密码的所以直接就可以进去了
- root@qiaowei-PC:/# MySQL
- Welcome to the MySQL monitor. Commands end with ; or \g.
- Your MySQL connection id is 2
- Server version: 5.7.21-1 (Debian)
- 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.
- Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
- MySQL> show databases;
- +--------------------+
- | Database |
- +--------------------+
- | information_schema |
- | MySQL |
- | performance_schema |
- | sys |
- +--------------------+
- 4 rows in set (0.03 sec)
- MySQL> exit
- Bye
那么接下来就是我们需要设置一个密码了! 首先静茹数据库
- >MySQL
- >show databases;
- MySQL> show databases;
- +--------------------+
- | Database |
- +--------------------+
- | information_schema |
- | MySQL |
- | performance_schema |
- | sys |
- +--------------------+
- 4 rows in set (0.03 sec)
这样我们就看到 4 张数据表了我们使用 MySQL
- >use MySQL;
- MySQL> use MySQL
- Reading table information for completion of table and column names
- You can turn off this feature to get a quicker startup with -A
- Database changed
- MySQL> show tables;
- +---------------------------+
- | Tables_in_mysql |
- +---------------------------+
- | columns_priv |
- | db |
- | engine_cost |
- | event |
- | func |
- | general_log |
- | gtid_executed |
- | help_category |
- | help_keyword |
- | help_relation |
- | help_topic |
- | innodb_index_stats |
- | innodb_table_stats |
- | ndb_binlog_index |
- | plugin |
- | proc |
- | procs_priv |
- | proxies_priv |
- | server_cost |
- | servers |
- | slave_master_info |
- | slave_relay_log_info |
- | slave_worker_info |
- | slow_log |
- | tables_priv |
- | time_zone |
- | time_zone_leap_second |
- | time_zone_name |
- | time_zone_transition |
- | time_zone_transition_type |
- | user |
- +---------------------------+
- 31 rows in set (0.00 sec)
我们需要使用 user 表, 因为该表里面存储了很多你的用户个人信息
接下来是非常重要的信息了!
我们要改密码了: 语法是 update user set plugin="mysql_native_password" where user="用户名";
该句可以更改用户名默认是 root
update user set authentication_string=password("密码") where user="用户名";
该句可以把上面的用户的密码重新设置一下
- MySQL> update user set plugin="mysql_native_password" where user="root";
- Query OK, 1 row affected (0.00 sec)
- Rows matched: 1 Changed: 1 Warnings: 0
- MySQL> update user set authentication_string=password("123456") where user="root";
- Query OK, 1 row affected, 1 warning (0.00 sec)
- Rows matched: 1 Changed: 1 Warnings: 1
这样就可以所完成了
最后我们使用登录就可以啦!
- qiaowei@qiaowei-PC:~/Desktop$ MySQL -u root -p
- Enter password:
- Welcome to the MySQL monitor. Commands end with ; or \g.
- Your MySQL connection id is 4
- Server version: 5.7.21-1 (Debian)
- 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.
- Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
- MySQL> exit
- Bye
MySQL -u 用户名 -p 密码
我们可以使用这段语句来登录 MySQL 数据库服务
ok 了! 第一次写博客有点紧张 哈哈哈
来源: http://www.bubuko.com/infodetail-2945888.html