Linux/Mysql: Difference between revisions

From Wiki
No edit summary
Line 40: Line 40:


== User Management ==
== User Management ==
=== Create User ===
<pre>
CREATE USER 'username'@'localhost' INDENTIFIED BY 'password'
CREATE USER 'username'@'%' IDENTIFIED BY 'password'
</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]]
[[Category:Linux/Services]]
[[Category:Linux/Services]]

Revision as of 10:45, 13 March 2019

List Databases

mysql -u root -p
show databases;
 
mysql -u root -p -e 'show databases;'
echo "show databases;" | mysql

Dump Database

mysqldump -u root -p databasename > databasename.sql

mysqldump -u root -p --quick --add-drop-table --complete-insert --allow-keywords databasename > databasename.sql

Dump Database from Docker

docker exec CONTAINER /usr/bin/mysqldump -u root --password=root DATABASE > backup.sql

Import Database

mysql -u root -p databasename < databasename.sql

Import Database in Docker

docker exec -i mysql-container mysql -uuser -ppassword name_db < data.sql

docker-compose:

    volumes:
        - ./dump.sql:/docker-entrypoint-initdb.d/dump.sql

User Management

Create User

CREATE USER 'username'@'localhost' INDENTIFIED BY 'password'
CREATE USER 'username'@'%' IDENTIFIED BY 'password'

Grant Access

GRANT ALL PRIVILIGES ON *.* to 'username'@'localhost' WITH GRANT OPTION;

Show Access Rights

SHOW GRANTS FOR 'username'@'localhost';