Commit 696494ff41ea0a97ea1c1012585c31aa0c3bde14

Authored by Etienne Pallier
1 parent daea334e
Exists in dev

debug mysql dans install.py

Showing 1 changed file with 24 additions and 12 deletions   Show diff stats
install/install.py
... ... @@ -269,7 +269,7 @@ def install_database(venv):
269 269 # --------------------------------------------
270 270 # --- Prepare the SQL query to create and initialize the pyros database if needed
271 271 # --------------------------------------------
272   - if sql_version<5.5:
  272 + if sql_version < 5.5:
273 273 #sql_query = "drop database "+SQL_DATABASE+" ; CREATE DATABASE "+SQL_DATABASE+"; drop database "+SQL_DATABASE_TEST+" ; CREATE DATABASE "+SQL_DATABASE_TEST+"; CREATE USER "+SQL_USER+" ; GRANT USAGE ON *.* TO '"+SQL_USER+"'@'localhost' IDENTIFIED BY '"+SQL_PSWD+"' WITH GRANT OPTION; DROP USER '"+SQL_USER+"'@'localhost'; GRANT ALL ON "+SQL_DATABASE+".* TO '"+SQL_USER+"'@'localhost' IDENTIFIED BY '"+SQL_PSWD+"'; GRANT ALL PRIVILEGES ON "+SQL_DATABASE+".* TO '"+SQL_USER+"'@'localhost' IDENTIFIED BY '"+SQL_PSWD+"' WITH GRANT OPTION; GRANT ALL PRIVILEGES ON "+SQL_DATABASE_TEST+".* TO "+SQL_USER+"@localhost IDENTIFIED BY '"+SQL_PSWD+"' WITH GRANT OPTION;"
274 274 sql_query = ""
275 275 sql_query += "drop database "+SQL_DATABASE+" ; CREATE DATABASE "+SQL_DATABASE+"; "
... ... @@ -279,17 +279,29 @@ def install_database(venv):
279 279 sql_query += "GRANT ALL ON "+SQL_DATABASE+".* TO '"+SQL_USER+"'@'localhost' IDENTIFIED BY '"+SQL_PSWD+"'; "
280 280 sql_query += "GRANT ALL PRIVILEGES ON "+SQL_DATABASE+".* TO '"+SQL_USER+"'@'localhost' IDENTIFIED BY '"+SQL_PSWD+"' WITH GRANT OPTION; "
281 281 sql_query += "GRANT ALL PRIVILEGES ON "+SQL_DATABASE_TEST+".* TO "+SQL_USER+"@localhost IDENTIFIED BY '"+SQL_PSWD+"' WITH GRANT OPTION; "
282   - else:
283   - # Ne marche pas sur mysql 5.5.60 :
284   - #"CREATE USER IF NOT EXISTS "+SQL_USER+"; " +\
285   - sql_query = "CREATE DATABASE IF NOT EXISTS " + SQL_DATABASE +"; " +\
286   - "CREATE DATABASE IF NOT EXISTS "+SQL_DATABASE_TEST+"; " +\
287   - "CREATE USER "+SQL_USER+"; " +\
288   - "GRANT USAGE ON *.* TO '"+SQL_USER+"'; " +\
289   - "DROP USER '"+SQL_USER+"'; " +\
290   - "GRANT ALL ON "+SQL_DATABASE+".* TO '"+SQL_USER+"'@'localhost' IDENTIFIED BY '"+SQL_PSWD+"'; " +\
291   - "GRANT ALL ON "+SQL_DATABASE_TEST+".* TO '"+SQL_USER+"'@'localhost'; " +\
292   - "GRANT ALL PRIVILEGES ON "+SQL_DATABASE_TEST+".* TO '"+SQL_USER+"'@'localhost'; " +\
  282 + else: # (EP 18/6/19, tout refait)
  283 + sql_query = \
  284 + "CREATE DATABASE IF NOT EXISTS " + SQL_DATABASE +"; " +\
  285 + "CREATE DATABASE IF NOT EXISTS " + SQL_DATABASE_TEST +"; "
  286 + if sql_version >= 5.7:
  287 + sql_create_user = "CREATE USER IF NOT EXISTS "+SQL_USER+"; "
  288 + else: # 5.5 <= version < 5.7
  289 + # Si user n'existe pas => est créé ; Si user existe => pas d'erreur ; DONC ok dans les 2 cas
  290 + sql_create_user = "GRANT ALL ON "+SQL_DATABASE+".* TO '"+SQL_USER+"'@'localhost' IDENTIFIED BY '"+SQL_PSWD+"'; "
  291 + sql_query += sql_create_user
  292 + # Ne marche pas si l'utilisateur existe déjà => erreur
  293 + #"CREATE USER "+SQL_USER+"; " +\
  294 + '''
  295 + # (EP) AVANT, y avait tout ça..., vraiment utile ?
  296 + "GRANT USAGE ON *.* TO '"+SQL_USER+"'; " +\
  297 + "DROP USER '"+SQL_USER+"'; " +\
  298 + "GRANT ALL ON "+SQL_DATABASE+".* TO '"+SQL_USER+"'@'localhost' IDENTIFIED BY '"+SQL_PSWD+"'; " +\
  299 + "GRANT ALL ON "+SQL_DATABASE_TEST+".* TO '"+SQL_USER+"'@'localhost'; " +\
  300 + "GRANT ALL PRIVILEGES ON "+SQL_DATABASE_TEST+".* TO '"+SQL_USER+"'@'localhost'; " +\
  301 + "GRANT ALL ON "+SQL_DATABASE_TEST+".* TO '"+SQL_USER+"'@'localhost' IDENTIFIED BY '"+SQL_PSWD+"' ;"
  302 + # J'ai simplifié comme ça :
  303 + '''
  304 + sql_query += \
293 305 "GRANT ALL ON "+SQL_DATABASE_TEST+".* TO '"+SQL_USER+"'@'localhost' IDENTIFIED BY '"+SQL_PSWD+"' ;"
294 306 # NEWER MYSQL:
295 307 # OLDER MYSQL: Try this instead for OLDER mysql (works on CentOS 6.4 and Centos 7.5 with mysql 5.5):
... ...