Install MySQL at WSL: Difference between revisions

From WikiMLT
m (Стадий: 3 [Фаза:Разработване, Статус:Разработван]; Категория:Databases)
mNo edit summary
 
(4 intermediate revisions by the same user not shown)
Line 1: Line 1:
<noinclude><!--[[Category:Databases|?]]-->{{ContentArticleHeader/Databases}}</noinclude>
<noinclude><!--[[Category:Databases|?]]-->{{ContentArticleHeader/Databases}}</noinclude>
== References ==


* ...
== Install MySQL ==
 
Install <code>mysql-server</code> and <code>mysql-client</code>.<syntaxhighlight lang="shell" class="code-continue" line="1">
sudo apt install -y mysql-client mysql-server
sudo service mysql start
sudo service mysql status
mysql --version
</syntaxhighlight>


* ...
== Setup a User with MySQL Native Authentication ==
Then create a MySQL user that is able to log-in into the MySQL server by using native authentication. Gran to the user all privileges.
<syntaxhighlight lang="shell" class="code-continue" line="1">
sudo mysql
</syntaxhighlight>
<syntaxhighlight lang="mysql" line="1" class="code-continue">
CREATE USER 'local_admin'@'localhost' IDENTIFIED WITH mysql_native_password BY 'local_admin_password_1!2@3#';
GRANT ALL PRIVILEGES ON *.* TO 'local_admin'@'localhost' WITH GRANT OPTION;
SELECT user,plugin,host FROM mysql.user WHERE host = 'localhost';
</syntaxhighlight><syntaxhighlight lang="text" highlight="5" class="code-continue">
+------------------+-----------------------+-----------+
| user            | plugin                | host      |
+------------------+-----------------------+-----------+
| debian-sys-maint | caching_sha2_password | localhost |
| local_admin      | mysql_native_password | localhost |
| mysql.infoschema | caching_sha2_password | localhost |
| mysql.session    | caching_sha2_password | localhost |
| mysql.sys        | caching_sha2_password | localhost |
| root            | auth_socket          | localhost |
+------------------+-----------------------+-----------+
6 rows in set (0.00 sec)
</syntaxhighlight>
<syntaxhighlight lang="mysql" line="1" start="4">
quit
</syntaxhighlight>
Now log-in by that user in order to test it and create one new empty data base for the further tests.
<syntaxhighlight lang="shell" class="code-continue" line="1">
mysql -u'local_admin' -p'local_admin_password_1!2@3#'
</syntaxhighlight>
<syntaxhighlight lang="mysql" line="1" class="code-continue">
CREATE DATABASE nodejs_w3s_tests;
</syntaxhighlight>
<syntaxhighlight lang="text" class="code-continue">
Query OK, 1 row affected (0.01 sec)
</syntaxhighlight>
<syntaxhighlight lang="mysql" line="1" start="2">
quit
</syntaxhighlight>
In order to start the MySQL server automatically at user log-in, create or update the file <code>wsl-services.bat</code>, located in the Windows user's folder <code>[https://www.softwareok.com/?seite=faq-Windows-10&faq=151 shell:startup]</code>, with the following entry.
<syntaxhighlight lang="shell" class="code-continue">
wsl-services.bat
</syntaxhighlight>
<syntaxhighlight lang="text">
C:\Windows\System32\wsl.exe -u root /etc/init.d/mysql start
</syntaxhighlight>


== Section 1 ==
== References ==
...
* [https://askubuntu.com/q/1382572/566421 Open Ubuntu terminal using batch file on windows with command?]
* [https://askubuntu.com/q/1165969/566421 Ubuntu 18.04 on WSL Cron daemon not running after reboot]
* [https://kontext.tech/column/sql-databases/615/install-mysql-on-wsl Context.tech: Install MySQL on WSL]


<noinclude>
<noinclude>
Line 13: Line 65:
{{devStage  
{{devStage  
  | Прндл  = Databases
  | Прндл  = Databases
  | Стадий = 3
  | Стадий = 6
  | Фаза  = Разработване
  | Фаза  = Утвърждаване
  | Статус = Разработван
  | Статус = Утвърден
  | ИдтПт  = Spas
  | ИдтПт  = Spas
  | РзбПт  = {{REVISIONUSER}}
  | РзбПт = Spas
| АвтПт  = Spas
| УтвПт = {{REVISIONUSER}}
  | ИдтДт  = 12.02.2023
  | ИдтДт  = 12.02.2023
  | РзбДт  = {{Today}}
  | РзбДт = 12.02.2023
| АвтДт  = 12.02.2023
| УтвДт = {{Today}}
  | ИдтРв  = [[Special:Permalink/32228|32228]]
  | ИдтРв  = [[Special:Permalink/32228|32228]]
  | РзбРв  = {{REVISIONID}}
  | РзбРв = [[Special:Permalink/32231|32231]]
| АвтРв  = [[Special:Permalink/32232|32232]]
| УтвРв = {{REVISIONID}}
}}
}}
</div>
</div>
</noinclude>
</noinclude>

Latest revision as of 11:53, 12 February 2023

In­stall MySQL

In­stall mysql-serv­er and mysql-client.

sudo apt install -y mysql-client mysql-server
sudo service mysql start
sudo service mysql status
mysql --version

Set­up a User with MySQL Na­tive Au­then­ti­ca­tion

Then cre­ate a MySQL user that is able to log-in in­to the MySQL serv­er by us­ing na­tive au­then­ti­ca­tion. Gran to the user all priv­i­leges.

sudo mysql
CREATE USER 'local_admin'@'localhost' IDENTIFIED WITH mysql_native_password BY 'local_admin_password_1!2@3#';
GRANT ALL PRIVILEGES ON *.* TO 'local_admin'@'localhost' WITH GRANT OPTION;
SELECT user,plugin,host FROM mysql.user WHERE host = 'localhost';
+------------------+-----------------------+-----------+
| user             | plugin                | host      |
+------------------+-----------------------+-----------+
| debian-sys-maint | caching_sha2_password | localhost |
| local_admin      | mysql_native_password | localhost |
| mysql.infoschema | caching_sha2_password | localhost |
| mysql.session    | caching_sha2_password | localhost |
| mysql.sys        | caching_sha2_password | localhost |
| root             | auth_socket           | localhost |
+------------------+-----------------------+-----------+
6 rows in set (0.00 sec)
quit

Now log-in by that user in or­der to test it and cre­ate one new emp­ty da­ta base for the fur­ther tests.

mysql -u'local_admin' -p'local_admin_password_1!2@3#'
CREATE DATABASE nodejs_w3s_tests;
Query OK, 1 row affected (0.01 sec)
quit

In or­der to start the MySQL serv­er au­to­mat­i­cal­ly at user log-in, cre­ate or up­date the file wsl-services.bat, lo­cat­ed in the Win­dows user's fold­er shell:startup, with the fol­low­ing en­try.

wsl-services.bat
C:\Windows\System32\wsl.exe -u root /etc/init.d/mysql start

Ref­er­ences