I. Linux kernel and released version uname-acatetcissue II. glibc version liblibcso6 --- dynamic link library without man function data III. MySQL version MySQL binary distribution version file name format: mysql-VERSION-OStargz for example: Linux-Gener 1. Linux kernel and release VERSION
Uname-
Cat/etc/issue
II. glibc version
/Lib/libc. so.6 --- dynamic link library without man function data
III. MySQL version
The file name format for MySQL binary distribution is: mysql-VERSION-OS.tar.gz
For example: Linux-Generic (glibc 2.5) (x86, 64bit), Compressed TAR Archive(mysql-5.6.16-linux-glibc2.5-x86_64.tar.gz)
1. Download
Http://dev.mysql.com/downloads/mysql/
2. check the directory in which rpm is packaged
Rpm-qpl MySQL-server-5.6.23-1.el6.i686.rpm | more
Rpm-qpl MySQL-client-5.6.23-1.el6.x86_64.rpm | more
3. change the rpm installation path
Rpm -- help
Rpm -- prefix -- relocate
Rpmbuild spec binary rpm
Yum install
IV. rpm installation
Rpm-ivh xxx. rmp
Rpm-pql xxx. rmp
Install and start a MySQL instance
1. install
Mysql_install_db -- defaults-file =/root/data/mysql3306/my. cnf -- basedir =/usr/-- datadir =/root/data/mysql3306/data
2. start
Mysqld_safe -- defaults-file =/root/data/mysql3306/my. cnf &
3. log on
Mysql-h127.0.0.1-uroot-P3306-p
V. installation demonstration:
1. disable mysql
Ps-ef | grep mysqld
Kill 3397 3801
2. Installation
Cat init3306
Sh init3306.sh
3. start
Cat start3306.sh
Sh start3306.sh
Note: For mysql_install_db (mysql_install_db is generated by installing the rpm Package), run the following command:
Rpm-pql MySQL-server-5.5.42-1.linux2.6.i386.rpm | grep install
Which mysql_install_db
4. View Logs
Tail-100f/root/data/mysql3306/log/alert. log
When a data dictionary does not exist, it is automatically created ....
5. View processes
Ps-ef | grep mysqld
Mysqld_safe is the parent process of mysqld
6. log on
Sh my3306.sh -- mysql-h127.0.0.1-uroot -- P3306
VI. script:
1. --- install mysql: init3306.sh
Rm-rf/root/data/mysql3306/data /*
Rm-rf/root/log/mysql3306/iblog /*
Rm-rf/root/log/mysql3306/binlog /*
Chmod-R 777/root/data/mysql3306/data/
Chmod-R 777/root/log/mysql3306/iblog/
Chmod-R 777/root/log/mysql3306/binlog/
Chmod 755/root/data/mysql3306/my. cnf
Mysql_install_db -- defaults-file =/root/data/mysql3306/my. cnf -- basedir =/usr/-- datadir =/root/data/mysql3306/data
Chmod-R 777/root/data/mysql/3306/data/
Chmod-R 777/root/log/mysql3306/iblog/
Chmod-R 777/root/log/mysql3306/binlog/
2. -- start mysql: start336.sh
Mysqld_safe -- defaults-file =/root/data/mysql3306/my. cnf &
3. -- log on to mysql: my3306.sh
Mysql-h127.0.0.1-uroot-P3306-p
------ Under research
Cd/root/data/mysql3306/data/mysql
Cd/root/data/mysql3306/data/performance_schema -- performance-related
Cd/root/data/mysql3306/data/test --- test Database
Cd/root/log/mysql3306/iblog/--- innodb's own data and logs
------ Understand my. cnf (multiple instances use ports for scoring)
Vi/root/data/mysql3306/my. cnf
[Client]
Port = 3306
Socket =/root/data/mysql3306/run/mysql. sock
[Mysql]
Port = 3306
Promprt =\\ u \\ d \\ r :\\ m :\\ s>
[Mysqld]
Default-storage-engine = INNODB
Character-set-server = iatin1
Explicit_defaults_for_timestamp = true
# Dir
Innodb_log_group_home_dir =/root/log/mysql3306/iblog
Innodb_data_home_dir =/root/log/mysql3306/iblog
Basedir =/usr
Datadir =/root/data/mysql3306/data
Tmpdir =/root/data/mysql3306/tmp
Slave_load_tmpdir =/root/data/mysql3306/tmp
Log-error =/root/data/mysql3306/log/alert. log
Slow_query_log_file =/root/data/mysql3306/log/slow. log
Relay_log_info_file =/root/log/mysql3306/binlog/relay-log.info.
Master-info-file =/root/log/mysql3306/binlog/master.info
Socket =/root/data/mysql3306/run/mysql. sock
Log-bin =/root/log/mysql3306/binlog
Relay-log =/root/log/mysql3306/binlog/relaylog
Innodb_force_recovery = 0
7. operate mysql
1. log on to mysql:
Local: mysql-u $ usrename-p $ password
Remote: mysql-u $ username-p $ passwrod-h $ ip
Multi-instance: mysql-u $ username-p $ passwrod-P $ port
2. user operation
(1) create a user
Method 1:
Insert into mysql. user (user, host, password) values ('mytest', 'localhost', password ('123 '));
Flush privilege;
Method 2: create user mystest @ '%' identified by '123 ';
(2) User authorization
Simple authorization
Grant all privileges on *. * to mytest @ localhost;
Grant insert, update, delete, select on *. * to mytest @ localhost;
Authorize and create a user
Grant all privileges on *. * to mytest @ localhost identified by '20140901'; -- Create a user and cache the user,
(Equivalent to: insert into mysql. user, flush privilege)
Grant all privileges on *. * to mytest @ localhost; -- object permission
Grant super on *. * to mytest @ '%'; -- system permission (supert is equivalent to dba permission in oracle)
3. practice
Show databases; -- View all databases
Use mysql; -- switch to mysql database
Use tables; -- tables in the mysql database
Select user, host, password from mysql. user; ---- query all mysql Users. this is created by mysql_install_db.
Grant all privilege on *. * to test_1 @ '%'; -- all indicates (select update, delete, alter admin, super_acl), first * user, second * object, % all hosts
Mysql-h127.0.0.1-utest_1 ---- use the user created by grant to log on to mysql
Select user (); --- Current user
Create database jianfeng; --- create a database (the database in mysql is similar to the schema in oracle
Create table user (id int) engine = innodb --- create a table;
Grant select on jianfeng. user to test_1 @ '%'; --- grant the query permission for the jianfeng. user table to the test_1 user
Insert into mysql. user (user, host, password) values ('test _ 2', '%', password ('000000'); -- Create a user named test_2 in this way, you have no permission for a problem.
Flush privileges; --- refresh the user permissions of the mysql. user table to the memory.
Show master status \ G;
Change master to xxx;
Show processlist; --- view the connection of the current user, in the thread format (similar to v $ session in oracle)
4. drop table processing
Rename table test_1 to test; (you can quickly switch back rename table test to test_1 ;)
Back up mysqldump: mysqldump-h127.0.0.1-uroot mydb gyj_t1>/tmp/gyj_t1. SQL
Drop table test;
5. Auto-increment primary key (it is best to define the primary key by yourself, and the system defaults to the global increment)
Create table test (id int primary key auto_increment, name varchar (100) engine = innodb;
Show create table test \ G;
Create index test_name_idx on test (name );
Show create table test \ G;
Insert into test (name) values ('test ');
Commit;
Select * from test;
6. alter table processing-the original data will be moved and data needs to be copied
Alter table test add coll int;
7. execution plan
Select * from test where id = 1 \ G;
Explain select * from test where id = 1;
Create index test_id_coll_idx on test (id, coll );
Explain select * from test where id = 1;
Create index test_col_name on test (coll, name );
Explain select * from test where coll> 10 and name = 'XX ';
Show create table test \ G;
Alter table test drop index test_name_idx;
Explain select * from test where coll> 10 and name> 'XX ';
8. Data export
(1) use dump to export data
Mysqldump-h127.0.0.1-uroot mydb gyj_t1>/tmp/xx. SQL
Drop table test;
Source/tmp/xx. SQL -- import data
(2) use select to export data
Select * from test into outfile '/tmp/yy. SQL ';
9. Data Migration
(1) shutdown mode
Mysqldump/loadata
(2) non-stop mode
Physical: standby database (Cascade 5.5 --> 5.6, backward compatible)
After the master database is read only, the slave database can digest the binlog transferred from the master database, and then switch the slave database to the master database.
Show variables like '% read % ';
Set global read_only = on;
Insert into test (name) values ('XX'); -- the root user cannot be used.
(3) small tables on different platforms: oracle ---> mysql
Script: synfull. pl
(4) migration of a large table on different platforms: incremental migration
A. migrate all data
B. Upload the logs generated during the migration process
C. apply increment
D. switch the lock table
(5) incremental
A. Oracle: Materialized view
B. MySQL: trigger
Create trigger tri_test
Before insert, delete, update
Insert test_log value (type, id );
End;
/
Insert into test values (1, 'XXX ');
Test_log value ('insert', '1 ');
Lock table test;
Application Switching
10. binlog
Reset master; -- clears the current binlog
Show binlog events;
Create table x1 (id int );
Show binlog events;
Insert into x1 values (1 );
Commit;
Show binlog events;
Similar to: mysqlbinlog-vvv binlog.00001>/tmp/binlog. log
Vi/tmp/binlog. log
WAL: write ahead log, log first
11. archiving
Flush logs;
Show master status;
Write ahead log. recover backup, duriably. undo acid mvcc
12. parameters and statistics
Show variables; ---- parameter
Show variables like '% bin % ';
Show status; ---- statistics
Show global status like '% insert % ';
Insert into test (name) values ('xxxxx ');
Show variables like '% default % ';
Set global default_storage_engine = myisam; --- the operation of the current session is not affected, and the newly established connection is affected.
Set session default_storage_engine = myisam; --- affects the operation of the current session
--- Connection pool
Max_connect
Min_connect
Max_idle
Time_out
Disconnect -- release