在python中执行mysql命令时出错

2024-10-05 12:17:37 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在写一个python3脚本来自动安装radius和daloradius。 在中间,我得到一些错误。我的代码是:

import subprocess
import os
import sys

# Updating Resources
os.system("sudo apt-get update -y")


#subprocess.call(["apt-get", "install", "freeradius"])

#Installing Radius & Dependencies
print("\n Installing Free Radius ... \n")
os.system("sudo apt-get install freeradius freeradius-mysql -y")
print("\nInstalling  LAMP  ... \n")
os.system("sudo apt-get install mysql-server mysql-client apache2 php5 libapache2-mod-php5 php5-mysql php5-common php5-gd php-pear php-db php-mail -y")
#os.system("sudo apt-get install python-dev libmysqlclient-dev python3-pip")
#os.system("sudo pip3 install mysqlclient")

#Creating A Database for radius server
os.system("mysql -h localhost -uroot -p123 -e 'CREATE DATABASE foo';")
os.system("mysql -h localhost -uroot -p123 -e 'CREATE USER 'radius2'@'localhost' IDENTIFIED BY 'radpass'';")
os.system("mysql -h localhost -uroot -p123 -e 'GRANT ALL PRIVILEGES ON `radius` . * TO 'radius2'@'localhost'';")

我在收到一个错误

^{pr2}$

错误是:

 You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'radpass' at line 1

Tags: installimportlocalhostgetserveros错误mysql

热门问题