mysql ist eine Datenbank.
mysql -e "SHOW TABLES;" -u root -p gogs
Mit mysqldump sichern.
mysqldump -u DB-USER -pPASSWD --default-character-set=latin1 DB -c | gzip -9 > backup.sql.gz mysql -u DB_USER -pPASSWD DB < backup.sql.gz
show DATABASES;
use MEINE_DB;
Vorher DB auswählen (use MeineDB;)
show tables;
DROP TABLE MeineTabelle; DROP TABLE (Meinetabelle1, MeineTabelle2);
Tabellen mit bestimmten Prefix löschen (quick & dirty):
show tables like 'prefix_%';
copy the results and paste them into a text editor or output the query to a file, use a few search and replaces to remove unwanted formatting and replace \n with a comma put a ; on the end and add drop table to the front.
you'll get something that looks like this:
drop table myprefix_1, myprefix_2, myprefix_3;
select * from pkme_formmaker_form;
select slug,data from pkme_formmaker_form;
update pkme_formmaker_form set data='{"classSfx":"","user_email_field":false"}' where slug='kontakt';
DELETE FROM ma_job WHERE job_id IN (620981, 620982, 620984, 620985, 620986)
Bestimmte Anzahl (ungeprüft!):
DELETE FROM ma_job limit 5;
Mit bestimmten Inhalten:
DELETE FROM orders WHERE id_users = 1 AND id_product = 2 LIMIT 1
CREATE DATABASE menagerie;
DROP DATABASE menagerie;
Falls im Namen der Datenbank ein Bindestrich ist, kommt es zu einer Fehlermeldung:
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near '-db' at line 1
Dann hilft es die DB in `` zu setzen, z.B.: `meineDB-db`
SELECT spalte1,spalte2,spalte3 FROM tabelle INTO OUTFILE '/tmp/mein.csv';
SELECT User FROM mysql.user;
Mehr Info:
select host, user, password from mysql.user;
SHOW GRANTS FOR user@localhost;
(im Beispiel alle Rechte für alle DB):
CREATE USER 'newuser'@'localhost' IDENTIFIED BY 'password'; GRANT ALL PRIVILEGES ON * . * TO 'newuser'@'localhost'; FLUSH PRIVILEGES;
GRANT [type of permission] ON [database name].[table name] TO ‘[username]'@'localhost';
REVOKE [type of permission] ON [database name].[table name] FROM ‘[username]'@‘localhost';
DROP USER 'demo'@'localhost';
ALTER USER 'MyUser'@'localhost' IDENTIFIED BY 'NewPassword';