Linux/Mysql: Difference between revisions

From Wiki
(Weiterleitung nach Mysql erstellt)
Tag: New redirect
 
(One intermediate revision by the same user not shown)
Line 1: Line 1:
== List Databases ==
#REDIRECT [[Mysql]]
<pre>
mysql -u root -p
show databases;
mysql -u root -p -e 'show databases;'
</pre>
 
<pre>
echo "show databases;" | mysql
</pre>
 
== Create Databas ==
<pre>
CREATE DATABASE database_name;
</pre>
 
== Dump Database ==
<pre>
mysqldump -u root -p databasename > databasename.sql
 
mysqldump -u root -p --quick --add-drop-table --complete-insert --allow-keywords databasename > databasename.sql
</pre>
 
=== Dump Database from Docker ===
<pre>
docker exec CONTAINER /usr/bin/mysqldump -u root --password=root DATABASE > backup.sql
</pre>
 
== Import Database ==
<pre>
mysql -u root -p databasename < databasename.sql
</pre>
 
=== Import Database in Docker ===
<pre>
docker exec -i mysql-container mysql -uuser -ppassword name_db < data.sql
</pre>
 
docker-compose:
<pre>
    volumes:
        - ./dump.sql:/docker-entrypoint-initdb.d/dump.sql
</pre>
 
== User Management ==
=== Create User ===
<pre>
CREATE USER 'username'@'localhost' INDENTIFIED BY 'password'
CREATE USER 'username'@'%' IDENTIFIED BY 'password'
</pre>
 
=== Change User Password ===
<pre>
ALTER USER 'username'@'localhost' IDENTIFIED BY 'newpassword';
</pre>
 
=== Grant Access ===
<pre>
GRANT ALL PRIVILIGES ON *.* to 'username'@'localhost' WITH GRANT OPTION;
</pre>
 
=== Show Access Rights ===
<pre>
SHOW GRANTS FOR 'username'@'localhost';
</pre>
 
 
[[Category:Linux]]
[[Category:Linux/Services]]

Latest revision as of 12:48, 10 June 2020

Redirect to: