安装
sudo apt install mysql-server
$ pip install gunicorn pymysql
安装过程中,系统会提示你为 MySQL 服务设置一个 root 密码。
安装完成后用以下命令进入数据库:
$ mysql -u root -p
输入密码后回看到这样的输出:
$ mysql -u root -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 3
Server version: 5.7.24-0ubuntu0.18.04.1 (Ubuntu)
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>
修改配置文件
配置文件的路径在 /etc/mysql.my.cnf
,需要修改配置可编辑该文件。
首先我们需要把数据库的编码改为 UTF-8,否则中文储存会出现乱码。
在配置文件添加以下代码:
[client]
default-character-set=utf8
[mysql]
default-character-set=utf8
[mysqld]
collation-server = utf8_unicode_ci
init-connect='SET NAMES utf8'
character-set-server = utf8
现在使用 show variables like '%character%';
命令查看数据库编码:
mysql> show variables like '%character%';
+--------------------------+----------------------------+
| Variable_name | Value |
+--------------------------+----------------------------+
| character_set_client | utf8 |
| character_set_connection | utf8 |
| character_set_database | utf8 |
| character_set_filesystem | binary |
| character_set_results | utf8 |
| character_set_server | utf8 |
| character_set_system | utf8 |
| character_sets_dir | /usr/share/mysql/charsets/ |
+--------------------------+----------------------------+
8 rows in set (0.02 sec)
网友评论