Mysql Proxy Lua successfully installed in Ubuntu 9.04

Source: Internet
Author: User
Tags import database

Ubuntu 9.04InstallMysql Proxy LuaIs the content to be introduced in this article, mainly to understandMysql ProxyInUbuntu 9.04The installation environment under and has passed the test. For details, see this article.

Install mysql

1,

 
 
  1. apt-get install mysql-server mysql-client libmysqlclient15-dev 

2. Enter

 
 
  1. mysql  mysql -uroot -p 

Password root

3. Reset the mysql user root password.

 
 
  1. GRANT ALL PRIVILEGES ON *.* TO root@localhost IDENTIFIED BY "123456"; 

4. Create a new database proxy

 
 
  1. create database proxy;   

5. create user test with full operation permissions on the proxy Database

 
 
  1. grant all privileges on proxy.* to test@localhost identified by "zhaogongyu"; 

6. Allow the test user to log on to MySQL from any machine.

 
 
  1. Step 1: grant all privileges on proxy. * to test @ "%" identified by "zhaogongyu ";
  2.  
  3. Step 2: $ sudo gedit/etc/mysql/my. cnf

Old Version

 
 
  1. skip-networking => #skip-networking 

New Version

 
 
  1. Bind-address = 127.0.0.1 => bind-address = IP address of your machine

This allows other machines to access MySQL.

7. Restart the mysql Command

 
 
  1. sudo /etc/init.d/mysql restart 

8. Start mysql at startup

 
 
  1. vim /etc/rc.local 

Add the following row to the last row.

 
 
  1. cd /usr/bin; /usr/bin/safe_mysqld --user=root &  
  2. exit 0 

Note: Remember to add cd/usr/local/mysql-5.1.36; and add a space after the sentence, otherwise it will cause the failure to automatically start

9. export data from the database

 
 
  1. mysqldump -uroot -p --default-character-set=latin1 --set-charset=gbk --skip-opt mydatabase > d.sql 

10. Create a new database

 
 
  1. create database 'newdata' default character set gbk collate gbk_chinese_ci; 

11. Import Database

 
 
  1. mysql -uroot -p --default-character=gbk -f newmydatabase >source d.sql ..>exit 

Install read/write splitting mysql-proxy

I. mysql

 
 
  1. 1. apt-get install mysql-server mysql-client libmysqlclient15-dev
  2.  
  3. 2. Go to mysql-uroot-p

Password root

3. Reset the mysql user root password.

 
 
  1. GRANT ALL PRIVILEGES ON *.* TO root@localhost IDENTIFIED BY "123456"; 

4. Create a new database proxy and create a table prodata

 
 
  1. create database proxy;   
  2. CREATE TABLE prodata (name VARCHAR(20), sex CHAR(1)); 

5. create user test with full operation permissions on the proxy Database

 
 
  1. grant all privileges on proxy.* to test@localhost identified by "zhaogongyu"; 

6. Allow the test user to log on to MySQL from any machine.

 
 
  1. Step 1: grant all privileges on proxy. * to test @ "%" identified by "zhaogongyu ";
  2.  
  3. Step 2: $ sudo gedit/etc/mysql/my. cnf

Old Version

 
 
  1. skip-networking => #skip-networking 

New Version

 
 
  1. Bind-address = 127.0.0.1 => bind-address = IP address of your machine

This allows other machines to access MySQL.

7. Restart the mysql Command

 
 
  1. sudo /etc/init.d/mysql restart 

Note: location after mysql Installation

Execution File

 
 
  1. /usr/bin/mysql 

Database

 
 
  1. /var/lib/mysql  
  2. /var/log/mysql 

Control File

 
 
  1. /etc/mysql/my.cnf   

Database command line operations

2. Create a database named MYSQLDATA

 
 
  1. mysql> CREATE DATABASE MYSQLDATA; 

3. Select the database you created

 
 
  1. Mysql> use mysqldata; (when you press the Enter key to see Database changed, the operation is successful !)

4. view the tables in the current database

 
 
  1. mysql> SHOW TABLES; 

5. Create a database table

 
 
  1. mysql> CREATE TABLE MYTABLE (name VARCHAR(20), sex CHAR(1)); 

6. display table structure:

 
 
  1. mysql> DESCRIBE MYTABLE; 

7. Add records to the table

 
 
  1. mysql> insert into MYTABLE values ("hyq","M"); 

8. load data into a database table in text format, for example, D:/mysql.txt)

 
 
  1. mysql> LOAD DATA LOCAL INFILE "D:/mysql.txt" INTO TABLE MYTABLE; 

9. Import the. SQL FILE command such as D:/mysql. SQL)

 
 
  1. mysql>use database;  
  2. mysql>source d:/mysql.sql; 

10. delete a table

 
 
  1. mysql>drop TABLE MYTABLE; 

11. Clear the table

 
 
  1. mysql>delete from MYTABLE; 

12. Update table data

 
 
  1. mysql>update MYTABLE set sex="f" where name='hyq';  
  2.  
  3. http://hi.baidu.com/selfcool/blog/item/a44e101fce79b1f2e0fe0b9d.html 

Ii. mysql-proxy

LUA file Introduction

 
 
  1. Http://www.oreillynet.com/pub/a/databases/2007/07/12/getting-started-with-mysql-proxy.html? Page = 1
  2.  
  3. 192.168.1.38 proxy
  4. 192.168.1.44 slaver slave
  5. 192.168.1.55 master host
  6.  
  7. Apt-get mysql-proxy

Configuration

1. read/write splitting script

Modify the default connection and perform a quick test. If this parameter is not modified, the read/write splitting takes effect only when the number of connections reaches.

 
 
  1. Vim/usr/share/mysql-proxy/rw-splitting.lua
  2. Proxy. global. config. rwsplit = {
  3. Min_idle_connections = 1, # The default value is 4.
  4. Max_idle_connections = 1, # The default value is 8.
  5.  
  6. Is_debug = false
  7. }

2. read/write splitting

 
 
  1. Mysql-proxy -- proxy-read-only-backend-addresses = 10.0.0.6: 3306 -- proxy-backend-addresses = 10.0.0.5: 3306
  2. -- Proxy-lua-script =/usr/share/mysql-proxy/rw-splitting.lua>/var/log/mysql-proxy/mysql-proxy.log &
  3.  
  4. New/var/log/mysql-proxy/and mysql-proxy.log adjustment attribute 775 belongs to chown R mysql. adm xx Group)
  5. Sudo mysql-proxy -- proxy-read-only-backend-addresses = 192.168.1.44: 3306
  6. -- Proxy-backend-addresses = 192.168.1.55: 3306
  7. -- Proxy-lua-script =/usr/share/mysql-proxy/rw-splitting.lua>/var/log/mysql-proxy/mysql-proxy.log &
  8. )

NOTE: If no 4040 error occurs after the sudo mysql-proxy Query Process is run, restart mysql (sudo/etc/init. d/mysql restart) and enter proxy settings.

3. View Processes

 
 
  1. netstat -ant  
  2. tcp  00 0.0.0.0:40400.0.0.0:*LISTEN   
  3. tcp  00 0.0.0.0:40410.0.0.0:*LISTEN  

Started successfully

You can remotely connect to a linux host and perform some read/write operations.

4. Test read/write splitting

Go to the mysql-proxy host

 
 
  1. a@a-desktop:/usr/share/mysql-proxy$ mysql -utest -p -P4040 -h192.168.1.38  
  2. Enter password:  
  3. Welcome to the MySQL monitor.  Commands end with ; or \g.  
  4. Your MySQL connection id is 25  
  5. Server version: 5.0.51a-3ubuntu5.4-log  
  6.  
  7. Type 'help;' or '\h' for help. Type '\c' to clear the buffer.  
  8.  
  9. mysql> use proxy;  
  10. Database changed 

Insert a record

 
 
  1. mysql> insert into prodata(name) values("zgy");  
  2. Query OK, 1 row affected (0.01 sec)  
  3.  
  4. mysql>select * from proxy;  
  5. Empty set (0.00 sec) 

No result is returned when data is inserted ~ The read/write splitting is correct ~~~~

Note: Sometimes data is displayed in the mysql_proxy (38) database. restart the system and restart mysql.

Go to the master write server (192.168.1.55) to view the data

 
 
  1. mysql -utest -p -h192.168.1.55  
  2. use proxy;  
  3. select * from prodata; 

Check that a record has been written.

Access the slave read server (192.168.1.44)

 
 
  1. mysql -utest -p -h192.168.1.44  
  2. use proxy;  
  3. select * from prodata; 

Because no data is displayed

It indicates that only the read and write operations are allowed.

Summary:Ubuntu 9.04InstallMysql Proxy LuaThe content of the successful test version has been introduced. I hope this article will help you!

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.