In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-03-09 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >
Share
Shulou(Shulou.com)06/01 Report--
Open source address https://github.com/mysql-inception/inception
Document address http://mysql-inception.github.io/inception-document/
Inception installation, download and decompression
] $wget https://github.com/mysql-inception/inception.git
] $pwd
/ inception
] $unzip inception-master.zip
Install Inception
] $cd / inception/inception-master/
# execute the following command to see the installation help
] $sh inception_build.sh
Usage: inception_build.sh builddir [platform (linux:Xcode)]
EXAPMLE: inception_build.sh debug [Xcode]
# install to. / yk directory
] $sh inception_build.sh yk
# description:
1.inception_build.sh actually encapsulates the steps of compiling and installing cmake & & make & & make install.
2.buliddir is the installation directory and platform is the platform (default linux)
3. If you make an error every time, you need to delete the compilation directory and execute it again, otherwise the execution will make an error.
4. There is no err in the compilation process, which means the installation is successful.
Configure Inception
# with MySQL type, you can specify a cnf configuration file
] $vim / etc/inc.cnf
[inception]
General_log=1
General_log_file=inception.log
Port=6669
Socket=/tmp/inc.socket
Character-set-client-handshake=0
Character-set-server=utf8
.
# this is just a simple configuration to start the Inception service. For more configuration options, please refer to the documentation
Start Inception
] $cd / inception/inception-master/yk/mysql/bin
] $nohup / Inception-- defaults-file=/etc/inc.cnf &
] $netstat-antpl | grep 6669
Tcp 0 0 0.0.0. 0 6669 0.0.0. 0 LISTEN 4598/Inception
At this point, you can see that port 6669 of inception is already running
Connect Inception
] $mysql-h227.0.0.1-P6669
Welcome to the MySQL monitor. Commands end with; or\ g.
Your MySQL connection id is 2
Server version: Inception2.1.23 1
... ..
Mysql > inception get variables; # get all variables and values of inception
+-+
| | Variable_name | Value |
+-+
| | autocommit | OFF |
| | bind_address | * | |
| | character_set_system | utf8 |
. ..
Inception is easy to use
1. Inception stipulates that the inception_magic_start; statement should be added at the beginning of the statement, and the inception_magic_commit; statement should be added at the end of the execution statement block. These two statements are legal, marked SQL statements that can be correctly parsed in Inception. All enclosed statements that need to be audited or executed must be followed by a semicolon, which is actually batch execution of SQL statements. (including use database statements should also be followed by a semicolon, which is different from the MySQL client), otherwise there will be syntax errors
2. Currently, execution only supports access to Inception through C _ Inception + interface and Python interface. This segment must be submitted to Inception once through the execution interface. After processing, Inception will return a result set to tell us what errors exist in these statements, or are completely normal, and so on.
/ *-- user=yujx;--password=xxxxxxxxxxx;--host=127.0.0.1;--enable-check;--port=3306;*/
Inception_magic_start
Use test
CREATE TABLE yujx (id int)
Inception_magic_commit
Here is an example of a Python program that executes the above statement:
] $cat inc-mysql.py
#! / usr/bin/env python
# coding=utf8
Import MySQLdb
Sql='''/*--user=yujx;--password=yujx;--host=127.0.0.1;--execute=1;--port=3306;*/\
Inception_magic_start;\
Use test;\
CREATE TABLE yujx (id int comment 'test' primary key) engine=innodb DEFAULT CHARSET=utf8mb4 comment' Test';\
Inception_magic_commit;'''
# print sql
Try:
Conn=MySQLdb.connect (host='127.0.0.1',user='',passwd='',db='',port=6669)
Cur=conn.cursor ()
Ret=cur.execute (sql)
Result=cur.fetchall ()
Num_fields = len (cur.description)
Field_names = [I [0] for i in cur.description]
Print field_names
For row in result:
Print row [0], "|", row [1], "|", row [2], "|", row [3], "|", row [4], "|", row [5], "|", row [6], "|, row [7]," | ", row [8]," | ", row [9]," | ", row [10]
Cur.close ()
Conn.close ()
Except MySQLdb.Error,e:
Print "Mysql Error% d:% s"% (e.args [0], e.args [1])
When creating a table statement as CREATE TABLE yujx (id int)
] $python inc-mysql.py
['ID',' stage', 'errlevel',' stagestatus', 'errormessage',' SQL', 'Affected_rows',' sequence', 'backup_dbname',' execute_time', 'sqlsha1']
1 | CHECKED | 0 | Audit completed | None | use test | 0 | '00.00' | None | 0 |
2 | CHECKED | 1 | Audit completed | Set engine to innodb for table 'yujx'.
Set charset to one of 'utf8mb4' for table' yujx'.
Set comments for table 'yujx'.
Column 'id' in table' yujx' have no comments.
Column 'id' in table' yujx' is not allowed to been nullable.
Set Default value for column 'id' in table' yujx'
Set a primary key for table 'yujx'. | | CREATE TABLE yujx (id int) | 0 | '00.01' | 127_0_0_1_3306_test | 0 |
CREATE TABLE yujx (id int) engine=innodb
] $python inc-mysql.py
['ID',' stage', 'errlevel',' stagestatus', 'errormessage',' SQL', 'Affected_rows',' sequence', 'backup_dbname',' execute_time', 'sqlsha1']
1 | CHECKED | 0 | Audit completed | None | use test | 0 | '00.00' | None | 0 |
2 | CHECKED | 1 | Audit completed | Set charset to one of 'utf8mb4' for table' yujx'.
Set comments for table 'yujx'.
Column 'id' in table' yujx' have no comments.
Column 'id' in table' yujx' is not allowed to been nullable.
Set Default value for column 'id' in table' yujx'
Set a primary key for table 'yujx'. | | CREATE TABLE yujx (id int) engine=innodb | 0 | '00.01' | 127_0_0_1_3306_test | 0 |
And so on, until the following complete creation statement is finally successful
CREATE TABLE yujx (id int comment 'test' primary key) engine=innodb DEFAULT CHARSET=utf8mb4 comment' Test'
] $python inc-mysql.py
['ID',' stage', 'errlevel',' stagestatus', 'errormessage',' SQL', 'Affected_rows',' sequence', 'backup_dbname',' execute_time', 'sqlsha1']
1 | RERUN | 0 | Execute Successfully | None | use test | 0 | '14642521283500' | None | 0.000 |
2 | EXECUTED | 0 | Execute Successfully | None | CREATE TABLE yujx (id int comment 'test' primary key) engine=innodb DEFAULT CHARSET=utf8mb4 comment' test'| 0 | '146425212835' 1' | 127_0_0_1_3306_test | 0.010 |
As above, it is the default inception audit rule, and users can customize some rules according to their actual situation.
Inception operation LOG
] $tail-f / inception/inception-master/yk/mysql/bin/inception.log
24 Query / *-user=yujx;--password=yujx;--host=127.0.0.1;--execute=1;--port=3306;*/ inception_magic_start; use test; CREATE TABLE yujx (id int) engine=innodb; inception_magic_commit
160526 16:42:08 25 Query set autocommit=0
25 Query / *-user=yujx;--password=yujx;--host=127.0.0.1;--execute=1;--port=3306;*/ inception_magic_start; use test; CREATE TABLE yujx (id int comment 'test' primary key) engine=innodb DEFAULT CHARSET=utf8mb4 comment' Test'; inception_magic_commit
160526 17:13:50 26 Query select @ @ version_comment limit 1
160526 17:13:54 26 Query inception get variables
Parameter variables supported by Inception
Reference: http://mysql-inception.github.io/inception-document/variables/
Description of Inception backup function
When Inception performs DML operations, it has a backup function. It stores all the rows modified by the current statement in a specified library. These libraries need to be specified through several parameters, which are:
Inception_remote_backup_host / / host of the remote backup library
Inception_remote_backup_port / / port of the remote backup library
Inception_remote_system_user / / A user of the remote backup library
Inception_remote_system_password / / password of the user above
1. These parameters can be specified directly on the command line or in the inc.cnf configuration file. Modifying these parameters requires a restart of the inception service.
2.Inception enables backup by default. You can use the parameter-- disable-remote-backup=1 to turn off backup.
3. If the affected table does not have a primary key, it will not be backed up
4.Inception backup users must have CREATE and INSERT. CREATE permissions are used to create tables or libraries, INSERT permissions are used to insert backup data, and other permissions are not required (perhaps temporarily)
5. The storage of backup data on the backup machine is one-to-one with the online modified library. However, because there are many machines (there are many online machines) to one (there is only one backup machine), in order to prevent library name conflicts, the library name of the backup machine is composed of an underscore from the dot of the IP address of the online machine, plus the port number, plus the three parts of the library name, which are also connected by underscores, such as 10_103_11_242_3306_test.
6. Requirements for online configuration
The online server must open binlog. When starting, you need to set the parameters log_bin, log_bin_index and other parameters about binlog. Otherwise, the rollback statement will not be backed up and generated.
The parameter binlog_format must be set to mixed or row mode, which is set by statement: set global binlog_format=mixed/row. If it is in statement mode, backup and rollback statements are not generated.
The parameter server_id must be set to non-0 and non-1, which is set by the statement: set global server_id=server_id;, otherwise an error will be reported during backup.
The online server must have the permission to specify the user name, which is specified in the comments in front of the statement. You must have the permission to do what you do, otherwise you will still report an error. If you need to perform functions, you must have the permission to execute statements online, such as DDL and DML. At the same time, if you want to execute remote commands such as inception show, some statements require special permissions, and these permissions also need to be granted. On the question of permissions, because Inception generally runs on a fixed machine, the user name and password specified in the option is actually the permission of the Inception machine to access the online database, so it is recommended to use a special fixed account for Inception to use, preferably a read-only and a writable one, so that it can be written during execution. It is safer to use read-only when reviewing or viewing online status or table library results.
Points that require extra attention
When executing, DML statements and DDL statements cannot be executed together, otherwise there will be unpredictable errors due to changes in table structure when the backup parses binlog. If you want to execute DML and DDL at the same time, please separate multiple statement blocks to execute. If you do so, Inception will report an error and will not execute it.
Backup function experiment backup server creates bakcup account and grant permissions
# all permission is enabled because of the test environment
Mysql > grant all on *. * to 'backup'@'%' identified by' backup'
Mysql > flush privileges
Specify backup server information
] $grep remote / etc/inc.cnf
Inception_remote_system_password=backup
Inception_remote_system_user=backup
Inception_remote_backup_port=3306
Inception_remote_backup_host=10.10.69.241
Restart inception
] $Kill-9 inception_pid
] $nohup / Inception-- defaults-file=/etc/inc.cnf &
Make sure the online target library binlog is open & & binlog_format
Mysql > show variables like 'log_bin'
+-+ +
| | Variable_name | Value |
+-+ +
| | log_bin | ON |
+-+ +
1 row in set (0.00 sec)
Mysql > show variables like 'binlog_format'
+-+ +
| | Variable_name | Value |
+-+ +
| | binlog_format | ROW |
+-+ +
1 row in set (0.00 sec)
Call inception operation target library
] $python inc-mysql.py
['ID',' stage', 'errlevel',' stagestatus', 'errormessage',' SQL', 'Affected_rows',' sequence', 'backup_dbname',' execute_time', 'sqlsha1']
1 | RERUN | 0 | Execute Successfully | None | use test | 0 | '1464320865 / 110.0' | None | 0.000 |
2 | EXECUTED | 0 | Execute Successfully
Backup successfully | None | CREATE TABLE yujx (id int comment 'test' primary key) engine=innodb DEFAULT CHARSET=utf8mb4 comment' Test'| 0 | '1464320865 / 11testing 1' | 127_0_0_1_3306_test | 0.010 |
View backup library
# as follows, 2 more db:inception and IP_PORT_DBNAME are added to the backup library
Mysql > show databases
+-+
| | Database |
+-+
| | information_schema |
| | 127_0_0_1_3306_test |
| | inception |
| | mysql |
| | performance_schema |
| | test |
+-+
# the inception.statistic table stores statistics on the number of SQL execution
Reference: http://mysql-inception.github.io/inception-document/statistic/
# the corresponding rollback operations are recorded in the following table of the IP_PORT_ dbName library
In addition to the one-to-one correspondence with the tables in the original library, there is another table in each backup library: $_ $Inception_backup_information$_$, which is the table name, which is very ugly, mainly to prevent conflicts with the table names in the original online library. This table is used to store all operation records for the current library. It is common, and all table operation records for the online library are stored here.
Reference link: http://mysql-inception.github.io/inception-document/backup/
Inception OSC function
Reference: http://mysql-inception.github.io/inception-document/osc/
Configure the path to PT-osc
] $which pt-online-schema-change
/ usr/bin/pt-online-schema-change
] $grep bin_dir / etc/inc.cnf
Inception_osc_bin_dir=/usr/bin/pt-online-schema-change
Set osc related options
] $grep osc inc-mysql-osc.py
Inception set session inception_osc_recursion_method=none
Inception set session inception_osc_alter_foreign_keys_method=0
When inception set session inception_osc_min_table_size=1; # sets the table size to exceed the value of this parameter, inception calls the osc tool alter table
Execute inception to call pt-osc
] $python inc-mysql-osc.py
['ID',' stage', 'errlevel',' stagestatus', 'errormessage',' SQL', 'Affected_rows',' sequence', 'backup_dbname',' execute_time', 'sqlsha1']
1 | RERUN | 0 | Execute Successfully | None | use test | 0 | '14643355782700' | None | 0.000 |
2 | EXECUTED | 0 | Execute Successfully
Backup successfully | None | alter table test add an int not null default 0 comment'a Field'| 1 | '1464335727' 270U1' | 127_0_0_1_3306_test | 149.880 | * 8388D07BAD14866D80DD45CD1521F4F0D17C20CE
Check the progress of osc
# View osc list
Mysql > inception get osc processlist
# from the processlist above, you can see the SQLSHA1 value corresponding to the osc task being executed, and then use the command below to view the progress of a specified osc task
Mysql > inception get osc_percent'* 8388D07BAD14866D80DD45CD1521F4F0D17C20CE'
+-+-
| | DBNAME | TABLENAME | SQLSHA1 | PERCENT | REMAINTIME | INFOMATION |
+-+- -| test | test | * 8388D07BAD14866D80DD45CD1521F4F0D17C20CE | 92 | 00:11 | Operation Tries, wait:
Copy_rows, 10, 0.25
Create_triggers, 10, 1
Drop_triggers, 10, 1
Swap_tables, 10, 1
Update_foreign_keys, 10, 1
No foreign keys reference `test`.`test`; ignoring-- alter-foreign-keys-method.
Altering `test`.`test`...
Creating new table...
CREATE TABLE `test`.` _ test_ New` (`x` int (11) DEFAULT NULL
`y`int (11) DEFAULT NULL
`z` int (11) NOT NULL AUTO_INCREMENT
PRIMARY KEY (`z`)
) ENGINE=InnoDB AUTO_INCREMENT=6488605 DEFAULT CHARSET=latin1
Created new table test._test_new OK.
Altering new table...
ALTER TABLE `test`.` _ test_ new` add an int not null default 0 comment'a murmur? μ'
Altered `test`.` _ test_ new` OK.
Creating triggers...
CREATE TRIGGER `pt_osc_test_test_ del`AFTER DELETE ON `test`.`test`FOR EACH ROW DELETE IGNORE FROM `test`.` _ test_ new`WHERE `test`.` _ test_ new`.`z`OLD.`z`
CREATE TRIGGER `pt_osc_test_test_ upd` AFTER UPDATE ON `test`.`test` FOR EACH ROW REPLACE INTO `test`.` _ test_ new` (`x`, `y`, `z`) VALUES (NEW.`y`, NEW.`z`)
CREATE TRIGGER `pt_osc_test_test_ ins` AFTER INSERT ON `test`.`test` FOR EACH ROW REPLACE INTO `test`.` _ test_ new` (`x`, `y`, `z`) VALUES (new.
Created triggers OK.
INSERT LOW_PRIORITY IGNORE INTO `test`.` _ test_ New` (`x`, `y`, `z`) SELECT `x`, `y`, `z`FROM `test`.`test` FORCE INDEX (`PRIMARY`) WHERE ((`z` > =?)) AND ((`z` =?)) ORDER BY `z` LIMIT?, 2 / * next chunk boundary*/
View the results of the target library
Mysql > desc test
+-+ +
| | Field | Type | Null | Key | Default | Extra | |
+-+ +
| | x | int (11) | YES | | NULL |
| | y | int (11) | YES | | NULL |
| | z | int (11) | NO | PRI | NULL | auto_increment |
| | a | int (11) | NO | | 0 | | # added successfully |
+-+ +
4 rows in set (0.01sec)
Inception auditing norms and principles
Reference http://mysql-inception.github.io/inception-document/rules/
The rules listed below may not necessarily cover all the functions currently implemented by Inception, including what rules they include. They also need to be summarized and found in the process of use. At the same time, you can learn more about these rules with configuration parameters.
Supported statement types
L use db: at this point, you will check whether the library exists or not, and you need to connect to the online server to determine.
L set option: now you only need to support set names charset, but do not support errors when setting other variables.
L create database statement
L insert statements (including multi-valued inserts)
L query insert statement
L delete statements (including multiple table deletions)
L update statements (including multi-table updates)
L create table statement
L delete table statement
L modify table statement
L Truncate table statement
L inception command set statements (including administrative commands)
Insert statement check item
Whether the l table exists
L must specify the insert list, that is, for which columns you want to specify insert values, such as insert into t (id,id2) values (...), (configurable)
L must specify a list of values, and the values inserted in the corresponding columns above must be specified.
L insert the same number of column lists as the values list, the number of the above two needs to be the same, and if no column list is specified (because it is configurable), the value list should be the same length as the number of table columns.
L is not a null column. If the inserted value is null, an error is reported (configurable)
L insert the column corresponding to the specified column name must exist.
L insert into the specified column list, the same column cannot appear more than once.
Simple expressions inserted into the values list are checked, but what is not specified one by one is included
Update and delete statement check items
Whether the l table exists
L must have where condition (configurable)
L delete statements cannot have limit conditions (configurable)
L cannot have order by statements (configurable)
L if the number of affected rows is more than 10000, the alarm will be given (the number can be configured)
L do a simple check on the expression WHERE condition, including what is not specified one by one
L do a simple check on the values list expression of the update column and do not specify one by one
L do a simple check on the update column object, mainly to check whether the column exists, etc.
L when multiple tables are updated or deleted, each table must exist
Create a table statement check item table property check item
L this table does not exist
For create table like, it checks whether the old table of like exists.
L for create table db.table, check whether the database db exists
L the length of table name, column name and index name is no more than 64 bytes
L if a temporary table is created, it must be prefixed with tmp
L must specify the storage engine that establishes the innodb (configurable)
L must specify the character set of the utf8 (the string is configurable to specify which character sets are supported)
L table must be annotated (configurable)
L table cannot be established as a partition table (configurable)
L can have only one self-increasing column
L index name cannot be Primay
L does not support Foreign key (configurable)
L when creating a table, if the specified value of auto_increment is not 1, an error is reported (configurable)
L if the name of the self-increment column is not id, it may be meaningful. It is dangerous to use MySQL in this way, so alarm (configurable)
Check items for column properties
Cannot set the character set of a column (configurable)
The type of l column cannot use collection, enumeration, or bitmap types. (configurable)
L column must have comments (configurable)
When the length of char is greater than 20, it needs to be changed to varchar (the length is configurable)
L column cannot be of type BLOB/TEXT. (configurable)
L use not null for each column (configurable)
If the column is of type BLOB/TEXT, the column cannot be set to NOT NULL.
If it is a self-incrementing column, use the unsigned type (configurable)
L if the column is self-incremented, the length must be greater than or equal to 4 bytes (configurable)
L if it is of type timestamp, you must specify a default value.
For databases below the MySQL5.5 version (including), you cannot have two columns of type TIMESTAMP at the same time, and if it is a type of DATETIME, it cannot be defined as statements such as DATETIME DEFAULT CURRENT_TIMESTAMP and ON UPDATE CURRENT_TIMESTAMP.
L default values need to be defined for each column, except for self-increment columns, primary key columns, and large field columns (configurable)
L cannot have duplicate column names
Index property check item
L index must have a name
L cannot have foreign keys (configurable)
L Unique index must be prefixed with uniq_ (configurable)
L normal indexes must be prefixed with idx_ (configurable)
The number of columns in the index cannot exceed 5 (the number can be configured)
L table must have a primary key (configurable)
L have up to 5 indexes (the number is configurable)
When indexing, the specified column must exist.
L columns in the index, which cannot be repeated
L BLOB column cannot be built as KEY
Index length cannot exceed 766
L cannot have duplicate indexes, names and contents
Default check item
L columns of type BLOB/TEXT, cannot have default values other than NULL
For versions below l MySQL5.5 (inclusive), you cannot have the default value of the function NOW () for columns of type DATETIME.
L if the default value is set to function, it can only be NOW ().
L if the default value is NULL, but the column type is NOT NULL, or the primary key column, or defined as a self-incrementing column, an error is reported.
L self-incrementing columns cannot set default values.
L modify table statement check item
Does the l table exist?
Create an index check item
L create the index check item in the table as above
Add check item
L create a column check item in the table as above
Modify table check items
Does the l table exist?
If there are multiple modification statements to the same table in the statement block, it is recommended to merge them into one ALTER statement.
Whether the column exists or not
The rest is the same as the above check items such as table creation, index creation, column creation, default value, etc.
Delete index check entry
Does the l table exist?
L check whether the index exists
Modify the default value check item for a column
L same default check item
Modify table properties
L table properties only support modifications to the storage engine, table comments, self-increment, and default character sets.
Check whether it is Innodb (configurable) when modifying the storage engine.
L character set modification check whether it belongs to the value of the setting parameter (the character set is configurable).
Conversion table character set
L character set modification check whether it belongs to the value of the setting parameter (the character set is configurable).
Statement
There are different processing strategies for whether the online MySQL server is above version 5.6 (inclusive). For example, when estimating the number of affected rows, 5.6 can directly perform EXPLAIN operations on any DML statement, while in version 5.5, only EXPLAIN operations are supported on SELECT statements, while in version 5.5, some DML statements are not easily converted to SELECT statements to do EXPLAIN, resulting in an estimated number of rows of 0.
Or for the difference between version 5.6 and version 5.5, DATETIME and TIMESTAMP series types have more restrictions on execution, while version 5.6 is basically general, so the above processing may be in versions 5.6 and 5.5, and the result set returned by the same statement is different (the rule is based on the error message in the execution Times in version 5.5), which has something to do with the online version.
Attached: three scripts executed to create the table
] $cat inc-mysql.py
#! / usr/bin/env python
# coding=utf8
Import MySQLdb
Sql='''/*--user=yujx;--password=yujx;--host=127.0.0.1;--execute=1;--port=3306;*/\
Inception_magic_start;\
Use test;\
CREATE TABLE yujx (id int comment 'test' primary key) engine=innodb DEFAULT CHARSET=utf8mb4 comment' Test';\
Inception_magic_commit;'''
# print sql
Try:
Conn=MySQLdb.connect (host='127.0.0.1',user='',passwd='',db='',port=6669)
Cur=conn.cursor ()
Ret=cur.execute (sql)
Result=cur.fetchall ()
Num_fields = len (cur.description)
Field_names = [I [0] for i in cur.description]
Print field_names
For row in result:
Print row [0], "|", row [1], "|", row [2], "|", row [3], "|", row [4], "|", row [5], "|", row [6], "|, row [7]," | ", row [8]," | ", row [9]," | ", row [10]
Cur.close ()
Conn.close ()
Except MySQLdb.Error,e:
Print "Mysql Error% d:% s"% (e.args [0], e.args [1])
Insert table
] $cat inc-mysql-insert.py
#! / usr/bin/env python
# coding=utf8
Import MySQLdb
Sql='''/*--user=yujx;--password=yujx;--host=127.0.0.1;--execute=1;--port=3306;*/\
Inception_magic_start;\
Use test;\
Insert into yujx (id) value (1);\
Inception_magic_commit;'''
# print sql
Try:
Conn=MySQLdb.connect (host='127.0.0.1',user='',passwd='',db='',port=6669)
Cur=conn.cursor ()
Ret=cur.execute (sql)
Result=cur.fetchall ()
Num_fields = len (cur.description)
Field_names = [I [0] for i in cur.description]
Print field_names
For row in result:
Print row [0], "|", row [1], "|", row [2], "|", row [3], "|", row [4], "|", row [5], "|", row [6], "|, row [7]," | ", row [8]," | ", row [9]," | ", row [10]
Cur.close ()
Conn.close ()
Except MySQLdb.Error,e:
Print "Mysql Error% d:% s"% (e.args [0], e.args [1])
OSC table
] $cat inc-mysql-osc.py
#! / usr/bin/env python
# coding=utf8
Import MySQLdb
Sql='''
Inception set session inception_osc_recursion_method=none
Inception set session inception_osc_alter_foreign_keys_method=0
Inception set session inception_osc_min_table_size=1
/ *-- user=yujx;--password=yujx;--host=127.0.0.1;--execute=1;--port=3306;*/\
Inception_magic_start;\
Use test;\
Alter table test add b int not null default 0 comment'b field';\
Inception_magic_commit;'''
Try:
Conn=MySQLdb.connect (host='127.0.0.1',user='',passwd='',db='',port=6669)
Cur=conn.cursor ()
Ret=cur.execute (sql)
Result=cur.fetchall ()
Num_fields = len (cur.description)
Field_names = [I [0] for i in cur.description]
Print field_names
For row in result:
Print row [0], "|", row [1], "|", row [2], "|", row [3], "|", row [4], "|", row [5], "|", row [6], "|, row [7]," | ", row [8]," | ", row [9]," | ", row [10]
Cur.close ()
Conn.close ()
Except MySQLdb.Error,e:
Print "Mysql Error% d:% s"% (e.args [0], e.args [1])
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.