-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
120 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -496,4 +496,9 @@ strconv | |
RGBA | ||
rect | ||
pbqr | ||
penpxrq | ||
penpxrq | ||
Goroutines | ||
|
||
mysqladmin | ||
devel | ||
mariadb |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,114 @@ | ||
# MySQL Basic | ||
|
||
A popular open source DBMS. | ||
|
||
* bought by Oracle | ||
* has open-source fork MariaDB | ||
|
||
## Common Packages | ||
|
||
```bash | ||
mysql | ||
mysql-sever | ||
mysql-devel | ||
|
||
mariadb-server | ||
``` | ||
|
||
secure | ||
|
||
```bash | ||
sudo mysql_secure_installation | ||
``` | ||
|
||
## Files | ||
|
||
Config file | ||
|
||
* e.g. can change the location of database files | ||
|
||
```bash | ||
/etc/my.cnf | ||
``` | ||
|
||
Database files | ||
|
||
* each directory represents a database with the same name | ||
* has some databases by default, like `mysql` and `test` | ||
|
||
```bash | ||
/var/lib/mysql/ | ||
``` | ||
|
||
Log | ||
|
||
```bash | ||
/var/log/mysqld.log | ||
``` | ||
|
||
## Network | ||
|
||
MySQL uses TCP protocol. | ||
|
||
The default port is 3306. | ||
|
||
## Basic Commands | ||
|
||
Use `mysqladmin` | ||
|
||
* if password is omitted, will prompt user to input later | ||
|
||
```bash | ||
mysqladmin -u root -p <some-password> <some-commend> | ||
mysqladmin --user=root --password=<some-old-password> password "some-new-password" # change password | ||
|
||
mysqldump -R some_db > dump | ||
``` | ||
|
||
Connect to local mysql server | ||
|
||
* -u user | ||
* -p login using password | ||
* -h specify host | ||
|
||
```bash | ||
mysql -u <some-user-name> -p | ||
> input your password | ||
|
||
mysql -h 192.168.1.1 -u root -p | ||
``` | ||
|
||
Cannot login unless `sudo`? | ||
|
||
[ERROR 1698 (28000): Access denied for user 'root'@'localhost'](https://stackoverflow.com/questions/39281594/error-1698-28000-access-denied-for-user-rootlocalhost) | ||
|
||
Log out mysql shell | ||
|
||
```sql | ||
mysql> | ||
mysql> quit | ||
``` | ||
|
||
Sample queries | ||
|
||
```sql | ||
SELECT VERSION(); | ||
SELECT CURRENT_DATE; | ||
|
||
SELECT VERSION(), CURRENT_DATE\g | ||
SELECT VERSION(), CURRENT_DATE\G | ||
|
||
SELECT 4+4; | ||
``` | ||
|
||
Databases commands | ||
|
||
```sql | ||
SHOW DATABASES; | ||
USE some_database; | ||
|
||
CREATE DATABASE some_database; | ||
DROP DATABASE some_database; | ||
``` | ||
|
||
[About renaming database](https://stackoverflow.com/questions/67093/how-do-i-quickly-rename-a-mysql-database-change-schema-name) |