i have a database and i give it name "test" then i try to change the database name using python code, but when i run the program the result give me an error warning. here is my code :
def changedb_name():
import mysql.connector
mydb = mysql.connector.connect(host = 'localhost', user='root', password ='')
mycursor = mydb.cursor()
mycursor.execute('ALTER DATABASE test RENAME to test1')
changedb_name()
here is the error warning :
Traceback (most recent call last):
File "c:\Users\NBUSER\Documents\ARTOFWAR\PITON\02-piton\aldo\chgdbname.py", line 18, in <module>
viewdb1()
File "c:\Users\NBUSER\Documents\ARTOFWAR\PITON\02-piton\aldo\chgdbname.py", line 15, in viewdb1
mycursor.execute('RENAME DATABASE test to test1')
File "C:\Users\NBUSER\AppData\Local\Programs\Python\Python39\lib\site-packages\mysql\connector\cursor.py", line 568, in execute
self._handle_result(self._connection.cmd_query(stmt))
File "C:\Users\NBUSER\AppData\Local\Programs\Python\Python39\lib\site-packages\mysql\connector\connection.py", line 846, in cmd_query
result = self._handle_result(self._send_cmd(ServerCmd.QUERY, query))
ion.py", line 656, in _handle_result
raise errors.get_exception(packet)
mysql.connector.errors.ProgrammingError: 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'DATABASE test to test1' at line 1
PS C:\Users\NBUSER\Documents\ARTOFWAR\PITON\02-piton> & C:/Users/NBUSER/AppData/Local/Programs/Python/Python39/python.exe c:/Users/NBUSER/Documents/ARTOFWAR/PITON/02-piton/aldo/chgdbname.py
Traceback (most recent call last):
File "c:\Users\NBUSER\Documents\ARTOFWAR\PITON\02-piton\aldo\chgdbname.py", line 18, in <module>
viewdb1()
File "c:\Users\NBUSER\Documents\ARTOFWAR\PITON\02-piton\aldo\chgdbname.py", line 15, in viewdb1
mycursor.execute('ALTER DATABASE test RENAME to test1')
File "C:\Users\NBUSER\AppData\Local\Programs\Python\Python39\lib\site-packages\mysql\connector\cursor.py", line 568, in execute
self._handle_result(self._connection.cmd_query(stmt))
File "C:\Users\NBUSER\AppData\Local\Programs\Python\Python39\lib\site-packages\mysql\connector\connection.py", line 846, in cmd_query
result = self._handle_result(self._send_cmd(ServerCmd.QUERY, query))
File "C:\Users\NBUSER\AppData\Local\Programs\Python\Python39\lib\site-packages\mysql\connector\connection.py", line 656, in _handle_result
raise errors.get_exception(packet)
mysql.connector.errors.ProgrammingError: 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'RENAME to test1' at line 1