-
Notifications
You must be signed in to change notification settings - Fork 7
/
mysql.sheet
59 lines (46 loc) · 1.79 KB
/
mysql.sheet
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
To create a database:
$ mysqladmin -u root create <database_name>
-
$ mysql --user=root
msql> CREATE DATABASE <database_name>;
msql> USE <database_name>;
msql> GRANT ALL PRIVILEGES ON *.* TO '<new_user>'@'localhost' IDENTIFIED BY '<new_user_password>' WITH GRANT OPTION;
msql> quit;
- msql> DROP DATABASE <database_name>;
----
Show databases, connect, show tables and table schema
msql> SHOW DATABASES;
msql> CONNECT <database_name>;
msql> SHOW TABLES;
msql> DESC <table_name>;
----
To SET a user password
mysql> use mysql;
mysql> update user set Password = PASSWORD('<password>') where host='<host_name>' and user='<user_name>';
mysql> flush privileges;
mysql> exit
$ mysqladmin -uroot -p<password> reload
----
To dump a database into an sql-text file
$ mysqldump --opt -u username -p database > database_backup.sql
---
To load a dump file into a database
$ mysql -u username -p database < dump_file.sql
-
Use the commandline tool mysqladmin
- the trick is to use 2 single-quotes (ticks) to specify an empty password:
Linux:
Note: you probably need to run this from the mysql bin dir:
$ cd /usr/local/mysql/bin
$ ./mysqladmin -uroot -p<existing_password> password ''
Windows:
Note: Use 2 double-quotes (windows doesn't trim out the single-quotes).
If you ran the Linux version ('') your password is now two single-quotes.
> mysqladmin -uroot -p<existing_password> password ""
To be prompted for password:
omit <existing_password>, but include the -p arg.
Inspired by http://www.delphifaq.com/faq/databases/mysql/f750.shtml
----
/G Display as table
mysql> select * from queries order by id desc limit 1 \G
(thx: http://rubyisawesome.com/2007/7/10/mysql-secrets-g-instead-of)