unbunt下安装mysql8.0

安装msyql

apt -get install mysql-server
apt install mysql-client-core-8.0

查看mysql启动状态

root@ubuntu:/home/lixuefu2# netstat -tap | grep mysql
tcp        0      0 localhost:33060         0.0.0.0:*               LISTEN      822424/mysqld       
tcp        0      0 localhost:mysql         0.0.0.0:*               LISTEN      822424/mysqld  
root@ubuntu:/home/lixuefu2# service mysql status
● mysql.service - MySQL Community Server
     Loaded: loaded (/lib/systemd/system/mysql.service; enabled; vendor preset: enabled)
     Active: active (running) since Sat 2022-02-12 17:40:32 CST; 1 day 15h ago
    Process: 822416 ExecStartPre=/usr/share/mysql/mysql-systemd-start pre (code=exited, status=0/SUCCESS)
   Main PID: 822424 (mysqld)
     Status: "Server is operational"
      Tasks: 40 (limit: 19086)
     Memory: 360.3M
     CGroup: /system.slice/mysql.service
             └─822424 /usr/sbin/mysqld

212 17:40:31 ubuntu systemd[1]: Starting MySQL Community Server...
212 17:40:32 ubuntu systemd[1]: Started MySQL Community Server.

命令行直接连接

直接mysql命令连接

root@ubuntu:/home/lixuefu2# mysql
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 31
Server version: 8.0.27-0ubuntu0.21.04.1 (Ubuntu)

Copyright (c) 2000, 2021, Oracle and/or its affiliates.

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> 

使用标准命令连接
mysql -uroot -p或mysql -h localhost -uroot -p

root@ubuntu:/home/lixuefu2# mysql -uroot -p
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 32
Server version: 8.0.27-0ubuntu0.21.04.1 (Ubuntu)

Copyright (c) 2000, 2021, Oracle and/or its affiliates.

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> 

创建mysql的新用户

这里如果使用root直接连接,会报错

django.db.utils.OperationalError: (1698, "Access denied for user 'root'@'localhost'")

所以需要创建一个新的用户
– 使用mysql数据库

use mysql

– 创建用户

mysql> CREATE USER dev IDENTIFIED BY '123456';
Query OK, 0 rows affected (0.01 sec)

– 授权用户

mysql> GRANT ALL ON *.* TO 'dev'@'%';
Query OK, 0 rows affected (0.00 sec)

–查看用户新建情况

mysql> select Host,user from user;
+-----------+------------------+
| Host      | user             |
+-----------+------------------+
| %         | dev              |
| %         | root             |
| localhost | debian-sys-maint |
| localhost | mysql.infoschema |
| localhost | mysql.session    |
| localhost | mysql.sys        |
+-----------+------------------+

pycharm启动django连接

mysql配置如下:

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.mysql',
        'NAME': 'django_mjtest_app_lab',
        'USER': 'dev',
        'PASSWORD': '123456',
        # 'HOST': '127.0.0.1',
        'HOST': 'localhost',
        'PORT': 3306,
    }
}

启动django

python manage.py runserver

February 14, 2022 - 09:31:04
Django version 3.2.12, using settings 'mjtest_app_lab.settings'
Starting development server at http://127.0.0.1:8000/
Quit the server with CONTROL-C.
python manegay runserver

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值