Skip to content

Commit

Permalink
update mysql
Browse files Browse the repository at this point in the history
  • Loading branch information
snowme34 committed Feb 2, 2019
1 parent 2d1ba38 commit fefce44
Show file tree
Hide file tree
Showing 2 changed files with 96 additions and 2 deletions.
4 changes: 3 additions & 1 deletion cspell_dict_bash.txt
Original file line number Diff line number Diff line change
Expand Up @@ -500,10 +500,12 @@ pbqr
penpxrq
Goroutines

mysqld
mysqladmin
devel
mariadb
SAVEPOINT
smallint
tinyint
varchar
varchar
mysqldump
94 changes: 93 additions & 1 deletion docs/source/reference/database/mysql/mysql-basic.md
Original file line number Diff line number Diff line change
Expand Up @@ -111,4 +111,96 @@ 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)
[About renaming database](https://stackoverflow.com/questions/67093/how-do-i-quickly-rename-a-mysql-database-change-schema-name)

## Simple Backup

```bash
mysqldump -u root -p some-database-name > some-backup-file-name.sql
mysql -u root -p some-database-name < some-backup-file-name.sql
```

## Character Set and Collation

A database uses specific encoding for the data.

Usually use different encoding for different languages

Why different?

* Storage size
* Communication between database and client

It should be

* The data are stored using the minimum space
* Same char set should be used otherwise the data will be garbled text

### MySQL

Default:

```markdown
char set: latin1
collation: latin1_swedish_ci
```

Char set and collation should be changed in the same time.

List supported char set

```sql
SHOW CHARACTER SET;
```

The most commonly used one is UTF-8.

List environment variables

```sql
SHOW VARIABLES;
```

List current config

```sql
SHOW VARIABLES LIKE 'character_set%';
SHOW VARIABLES LIKE 'collation%';
```

Specify when creating databases

```sql
CREATE DATABASE db DEFAULT CHARACTER_SET utf8 DEFAULT COLLATE utf8_general_ci;
```

Change existing ones

* Note the existing records might not be encoded correctly
* They must be dropped and recreated

```sql
ALTER DATABASE db CHARACTER SET utf8 COLLATE utf8_general_ci;
```

### Default Character Set and Collation Config

The file is located at `/etc/my.cnf`.

```conf
[client]
default-character-set=utf8
[mysql]
default-character-set=utf8
[mysqld]
default-character-set=utf8
collation-server=uft8_unicode_ci
init-connect='SET NAMES utf8'
character-set-server=utf8
```

Reload mysql after changing

[MySQL :: MySQL 8.0 Reference Manual :: 4.2.7 Using Option Files](https://dev.mysql.com/doc/refman/8.0/en/option-files.html)

0 comments on commit fefce44

Please sign in to comment.