MySQL installation and configuration process

mysql installation and configuration process


apt-get install mysql-server-5.6
sudo apt-get install mysql-client
sudo apt-get install libmysqlclient-dev

Check whether there is MySQL service in the system, the following is probably successful
netstat -tap|grep mysql
tcp 0 0 *:mysql *:* LISTEN 6153/mysqld #Start


mysql
start mysql #Close
mysql
stop The mysql


configuration file my.cnf
/etc/mysql/my.cnf

allows the server to be accessed remotely, or the configuration file my.cnf, also To the following configuration
#comment bind-address
#bind-address=127.0.0.1

reference: http://www.cnblogs.com/liuchangchun/p/4099003.html
http://www.linuxidc.com/Linux/2016- 07/133128.htm


local access to
mysql -u root -p test -h 127.0.0.1


Open remote access:
Method 1. Change the table method. It may be that your account is not allowed to log in from the remote, only on localhost. At this time, as long as you are on the localhost computer, after logging in to mysql, change the "host" item in the "user" table in the "mysql" database, from "localhost" to "%"
mysql -u root -pvmware
mysql>use mysql ;
mysql>update user set host = '%' where user = 'root';
mysql>select host, user from user;

Method 2. Authorization method. For example, if you want myuser to connect to the mysql server from any host using mypassword.
GRANT ALL PRIVILEGES ON *.* TO 'myuser'@'%' IDENTIFIED BY 'mypassword' WITH GRANT OPTION;

Method 3. If you want to allow user myuser to connect to mysql server from host with ip 192.168.33.60 and use mypassword as PasswordGRANT
ALL PRIVILEGES ON *.* TO 'root'@'192.168.33.60′ IDENTIFIED BY 'mypassword' WITH GRANT OPTION;

GRANT ALL PRIVILEGES ON *.* TO 'root'@'192.168.33.61′ IDENTIFIED BY '123456' WITH GRANT OPTION;

restart after modification;

Reference: http://www.111cn.net/database/mysql/75868.htm



open bin-log:
configuration file my.cnf, these configurations are open;
log_bin = /var/log/mysql/mysql-bin.log // Storage directory
expire_logs_days = 10 //Indicates that binary files that are exactly n days before the current time will be automatically deleted by the system, and 0 means not deleted.
max_binlog_size = 100M//The size of a log.
binlog_format = MIXED


show binary logs; #Display binlog file
purge binary logsto 'mysql-bin.**' #Delete to ** file

View the contents of the specified binlog file:
show binlog events in "mysql-bin.000003";

View the current running The written binlog file:
show master status

Get the contents of the binlog at the specified location:
show binlog events from 213

flush logs; #Close the current binary log file and create a new file, the name of the new binary log file is in the current binary file Add 1 to the number.


Extract the specified binlog log
mysqlbinlog /var/log/mysql/mysql-bin.000003

Extract the binlog log of the specified position
mysqlbinlog --start-position="120" /var/log/mysql/mysql-bin.000003


Extract the specified database binlog and convert the character set to UTF8
mysqlbinlog --database=test --set-charset=utf8 /var/log/mysql/mysql-bin.000003 > /home/test.sql
mysqlbinlog --database=test --set-charset=utf8 /opt/ data/APP01bin.000001 /opt/data/APP01bin.000002 >test.sql





for data recovery;
mysqlbinlog --no-defaults /var/log/mysql/mysql-bin.000003 --start-position="2973" -- stop-position="3828" | /usr/bin/mysql -uroot -p123456 test -h 127.0.0.1

mysqlbinlog --start-position="657" --stop-position="1840" /var/log/mysql/ mysql-bin.000003 | mysql -uroot -p123456 test

reference: http://www.2cto. com/database/201412/361968.html



mysqldump is often used for MySQL database logical backup
mysqldump -uroot -pPassword [database name] > [dump file]
mysqldump -uroot -p123 test > test.dump
mysqldump -uroot -p123456 --all-databases --flush-logs > /home/ mysql.bak
mysqldump -uroot -p123456 --databases test --flush-logs > /home/mysql.bak
mysqldump -uroot -p123456 --databases test --flush-logs --master-data=2 > /home/mysql The .bak
--master-data=2 option will record the name of the new log file after the full backup in the output SQL.


If you want to back up all databases on a MySQL host, you can use the --all-databases option, as follows:
mysqldump --all-databases > test.dump

mysqldump -uroot -p123456 --all-databases > /home/mysql.bak


restore database mysql from backup file
mysql [database name] < [backup file name]
mysqldump -u username -p password - h host database < path
mysql -uroot -p1234 db1 < c:\a.txt
mysql -uroot -p123456 < /home/mysql.bak //-databases already contains the database language name


Reference : http://www.cnblogs.com/feichexia/ p/MysqlDataBackup.html (timed backup)
Reference: http://www.cnblogs.com/qq78292959/p/3637135.html
Reference: http://blog.csdn.net/jesseyoung/article/details/41078947
Reference: https ://segmentfault.com/a/1190000002428533


scheduled backup
mysqldump -u root -pPASSWORD --all-databases | gzip > /mnt/disk2/database_`date '+%m-%d-%Y'`.sql.gz

Example of a complete shell script to backup a MySQL database
#vi /backup/backup.sh

#!bin/bash
cd /backup
echo "You are in backup dir"
mv backup* /oldbackup
echo "Old dbs are moved to oldbackup folder"
File = backup-$Now.sql
mysqldump -u user -p password database-name > $File
echo "Your database backup successfully completed" The

above script file is saved as backup.sh, and two directories /olcbackup and /backup have been created in the system. Every time backup.sh is executed, all files starting with backup in the /backup directory will be moved to the /oldbackup directory.

The execution plan for the above script is as follows:

#crontab -e
30 1 * * * /backup.sh

Reference: http://www.cnblogs.com/feichexia/p/MysqlDataBackup.html (timed backup)
Reference: http:// blog.csdn.net/gredn/article/details/54582993
Reference: http://www.cnblogs.com/lhj588/archive/2012/02/20/2359172.html (detailed explanation of Cron timing task system commands in linux)


Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326301157&siteId=291194637