資料庫維運
- Copy MySQL Database From One Server To Another Remote Server
- How to export database from Amazon RDS MySQL instance to local instance?
- MySQL: ignore errors when importing?
- Migrating MySQL Databases with No Downtime – For Non-DBAs
- SHOW BINARY LOGS Statement
- mysqlbinlog 資料庫處理二進制日誌檔案的實用工具
- MySQL Connection Handling and Scaling
- HA
User
How to Create MySQL Users Accounts and Grant Privileges
create a user that can connect from any host, use the '%' wildcard
random password ```bash= openssl rand -base64 12
### Grant Privileges
Grand all privileges to a user account over a specific database
``` sql
GRANT ALL PRIVILEGES ON database_name.* TO 'database_user'@'localhost';
Create Database
``sql=
CREATE SCHEMA IF NOT EXISTS
database_name` DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci
## 1040 Too many connections
To get total number of concurrent connections allowed
```mysql=
SHOW VARIABLES LIKE "max_connections";
how many concurrent connections are being used currently ```mysql= SHOW STATUS LIKE "max_used_connections";
- [Monitoring used connections on mysql to debug 'too many connections'](https://stackoverflow.com/questions/2453308/monitoring-used-connections-on-mysql-to-debug-too-many-connections)
- [Max_used_connections](https://dev.mysql.com/doc/refman/8.0/en/server-status-variables.html#statvar_Max_used_connections)
```mysql=
show variables like "%max_connections%";
show global status like "%Max_used%";
show status like "%thread%";
mysqldump
Skip certain tables with mysqldump
migration.conf
database=test
prev=bar.internal.foo.com
prev_bar=bar.internal.foo.com
next=bar-rds.internal.foo.com
user=foo
dump_dir=dump
db_migration.sh ``` bash=
!/bin/bash
env=$1 source migration.conf read -sp 'Please input database password: ' db_password
if [[ ! -d ${dump_dir} ]]; then mkdir ${dump_dir} else rm -rf ${dump_dir} mkdir ${dump_dir} fi
SECONDS=0 source create_db.sh source test.sh duration=$SECONDS echo "$(($duration / 60)) minutes and $(($duration % 60)) seconds elapsed."
test.sh
``` bash=
#!/bin/bash
echo "export score db $database start: "$(date)
mysqldump -h ${env}-${prev_scoredb} \
-u ${user} \
-p${db_password} \
--databases $database \
--single-transaction \
--order-by-primary \
--result-file ${dump_dir}/${database}_SCORE_DB.sql
echo "export $database done: "$(date)
echo "import score db $database start: "$(date)
mysql -h ${env}-${next} -u ${user} -p${db_password} -f < ${dump_dir}/${database}_SCORE_DB.sql
echo "import $database done: "$(date)
Change character set
- (MySQL 5.7.19 AWS RDS) how to change table column character set without locking
- is this a safe way to change character set on a MySQL table to UTF-8
- which is the better way to change the character set for huge data tables
- Changing character set of MySQL tables
- How to change the CHARACTER SET (and COLLATION) throughout a database?