Redhat7 python3 django安装使用mysql mariadb

在Redhat7上安装Django时遇到问题,原本的MySQL无法启动,改用Mariadb并成功启动。在Python3环境中安装MySQL-python模块时因不兼容而选择安装mysql-connector和pymysql。通过修改Django的settings.py文件解决密码验证和Django版本导致的中间件配置问题。最后,展示了如何进行Mariadb的基本数据库操作。
摘要由CSDN通过智能技术生成
  • yum install mysql mysql-server -y
  • service mysql start  报错
[root@hz-build-cloud-cbts02-okqvd ~]# service mysql start
Redirecting to /bin/systemctl start mysql.service
Failed to start mysql.service: Unit not found.


[root@hz-build-cloud-cbts02-okqvd ~]# mysql
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2)
[root@hz-build-cloud-cbts02-okqvd ~]# ls /var/lib/mysql/
[root@hz-build-cloud-cbts02-okqvd ~]# vi /etc/my.cnf
[root@hz-build-cloud-cbts02-okqvd ~]# ls /var/lib/mysql/my.cnf
ls: cannot access /var/lib/mysql/my.cnf: No such file or directory
[root@hz-build-cloud-cbts02-okqvd ~]# ls /etc/init.d/mysql
ls: cannot access /etc/init.d/mysql: No such file or directory
  • 尝试卸载mysql-server,安装mariadb, 启动mariadb服务即可。
[root@hz-build-cloud-cbts02-okqvd ~]# yum remove mysql-server
[root@hz-build-cloud-cbts02-okqvd ~]# yum erase mysql-community-common.x86_64
[root@hz-build-cloud-cbts02-okqvd ~]# yum list installed |grep mysql
mysql57-community-release.noarch   el7-9                    installed           
[root@hz-build-cloud-cbts02-okqvd ~]# yum erase mysql57-community-release.noarch

[root@hz-build-cloud-cbts02-okqvd ~]#  yum install mariadb  mariadb-libs mariadb-server -y
Loaded plugins: langpacks, product-id, search-disabled-repos, subscription-manager
This system is not registered with an entitlement server. You can use subscription-manager to register.
Package 3:mariadb-10.1.20-2.el7.x86_64 already installed and latest version
Package 3:mariadb-libs-10.1.20-2.el7.x86_64 already installed and latest version
Package 3:mariadb-server-10.1.20-2.el7.x86_64 already installed and latest version
Nothing to do
[root@hz-build-cloud-cbts02-okqvd ~]# systemctl start mariadb.service
[root@hz-build-cloud-cbts02-okqvd ~]# systemctl enable mariadb.service
Created symlink from /etc/systemd/system/multi-user.target.wants/mariadb.service to /usr/lib/systemd/system/mariadb.service.
[root@hz-build-cloud-cbts02-okqvd ~]# 
[root@hz-build-cloud-cbts02-okqvd ~]# mysql
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 2
Server version: 10.1.20-MariaDB MariaDB Server

Copyright (c) 2000, 2016, Oracle, MariaDB Corporation Ab and others.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

MariaDB [(none)]>
  • mysql安装成功后,启用django服务,报错如下,考虑安装MySQL-python模块:
  File "/usr/lib64/python3.4/site-packages/django/db/models/options.py", line 205, in contribute_to_class
    self.db_table = truncate_name(self.db_table, connection.ops.max_name_length())
  File "/usr/lib64/python3.4/site-packages/django/db/__init__.py", line 33, in __getattr__
    return getattr(connections[DEFAULT_DB_ALIAS], item)
  File "/usr/lib64/python3.4/site-packages/django/db/utils.py", line 202, in __getitem__
    backend = load_backend(db['ENGINE'])
  File "/usr/lib64/python3.4/site-packages/django/db/utils.py", line 110, in load_backend
    return import_module('%s.base' % backend_name)
  File "/usr/lib64/python3.4/importlib/__init__.py", line 109, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "/
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值