3434use OC \DB \MySqlTools ;
3535use OCP \IDBConnection ;
3636use OCP \ILogger ;
37+ use Doctrine \DBAL \Platforms \MySQL80Platform ;
3738
3839class MySQL extends AbstractDatabase {
3940 public $ dbprettyname = 'MySQL/MariaDB ' ;
@@ -57,6 +58,16 @@ public function setupDatabase($username) {
5758 //fill the database if needed
5859 $ query ='select count(*) from information_schema.tables where table_schema=? AND table_name = ? ' ;
5960 $ connection ->executeQuery ($ query , [$ this ->dbName , $ this ->tablePrefix .'users ' ]);
61+
62+ $ connection ->close ();
63+ $ connection = $ this ->connect ();
64+ try {
65+ $ connection ->connect ();
66+ } catch (\Exception $ e ) {
67+ $ this ->logger ->logException ($ e );
68+ throw new \OC \DatabaseSetupException ($ this ->trans ->t ('MySQL username and/or password not valid ' ),
69+ $ this ->trans ->t ('You need to enter details of an existing account. ' ));
70+ }
6071 }
6172
6273 /**
@@ -102,10 +113,18 @@ private function createDBUser($connection) {
102113 $ password = $ this ->dbPassword ;
103114 // we need to create 2 accounts, one for global use and one for local user. if we don't specify the local one,
104115 // the anonymous user would take precedence when there is one.
105- $ query = "CREATE USER ' $ name'@'localhost' IDENTIFIED WITH mysql_native_password BY ' $ password' " ;
106- $ connection ->executeUpdate ($ query );
107- $ query = "CREATE USER ' $ name'@'%' IDENTIFIED WITH mysql_native_password BY ' $ password' " ;
108- $ connection ->executeUpdate ($ query );
116+
117+ if ($ connection ->getDatabasePlatform () instanceof Mysql80Platform) {
118+ $ query = "CREATE USER ' $ name'@'localhost' IDENTIFIED WITH mysql_native_password BY ' $ password' " ;
119+ $ connection ->executeUpdate ($ query );
120+ $ query = "CREATE USER ' $ name'@'%' IDENTIFIED WITH mysql_native_password BY ' $ password' " ;
121+ $ connection ->executeUpdate ($ query );
122+ } else {
123+ $ query = "CREATE USER ' $ name'@'localhost' IDENTIFIED BY ' $ password' " ;
124+ $ connection ->executeUpdate ($ query );
125+ $ query = "CREATE USER ' $ name'@'%' IDENTIFIED BY ' $ password' " ;
126+ $ connection ->executeUpdate ($ query );
127+ }
109128 }
110129 catch (\Exception $ ex ){
111130 $ this ->logger ->logException ($ ex , [
0 commit comments