Install MySql in two different versions in Linux (mysql5 and mysql4)

Source: Internet
Author: User

Cause of the problem: a set of web programs have been run on the existing Red Hat Enterprise Linux as 3.0 system. mysql4 and tomcat41 are used. Now a new program is required to be installed and the tomcat41 is still used, but the database changes to mysql5.

Note:
Attention should be paid to character sets in new programs,
1) permissions and groups of specific databases,
2) It is difficult to copy a specific database under mysql5 from windows to Linux,
3) and mysql5 password settings,
4) MySQL 5 is case sensitive to databases in Linux.
5) MySQL enters the terminal
Mysql>
User name and password Problems

In addition, when installing mysql5, you must modify the installation location of mysql5 (basedir), database storage location (datadir), and port number (changed to 3307, in this way, we can ensure that two different versions of databases run simultaneously.

Version:
MySQL v4.0.24
(1) MySQL-server-4.0.24-0.i386.rpm
(2) MySQL-client-4.0.24-0.i386.rpm
(3) MySQL-devel-4.0.24-0.i386.rpm
MySQL 5.0.51a
Mysql-5.0.51a.tar.gz
: Http://ftp.ntu.edu.tw/pub/MySQL/Downloads/MySQL-5.0/mysql-5.0.51a.tar.gz

Install MySQL v4.0.24
# Rpm-Qa | grep SQL
Check whether the MySQL server is installed by default in the query system.
Then uninstall the MySQL instance installed by default.
Run the following command to uninstall MySQL:
# Rpm-e -- nodeps mysql-3.23.58-1

Install MySQL Server:
# Rpm-IVH MySQL-server-4.0.24-0.i386.rpm
Test whether the server is successfully installed:
# Netstat-Nat
Check whether port 3306 is enabled
Then install the mysql client
# Rpm-IVH MySQL-client-4.0.24-0.i386.rpm
Install the MySQL connection package:
# Rpm-IVH MySQL-devel-4.0.24-0.i386.rpm
The installation paths of mysql4 are as follows:
Take the MySQL 4.0.26 database installed in RedHat as an example:
(Note: The RPM package uses default settings and cannot be changed. The following are default settings)
1. configuration file:/etc/My. CNF
2. Database Directory:/var/lib/MySQL
3. Startup Script:/etc/rc. d/init. d/MySQL
4. Port 3306
5. Socket file/tmp/MySQL. Socket
--------------------------------------

Install MySQL 5.0.51a below

Because the installation package type of mysql4.0.26 we installed is rpm, you must note that,
It uses default settings. After installation, the configuration files, database directories, and a series of other configurations cannot be changed.
Therefore, to install two databases in the same development environment, we must solve the following problems:
1. The installation path of the configuration file cannot be the same
2. The database directory cannot be the same
3. the startup script cannot have the same name.
4. ports cannot be the same
5. The path for generating the socket file cannot be the same
According to the above requirements: Install the source code package of mysql5.0.51a.tar.gz and make the following adjustments:
-- Prefix =/usr/local/mysql5 ### database installation directory
-- Localstatedir =/var/lib/mysql5 ### database storage directory
-- With-charset = GBK -- With-collation = gbk_chinese_ci -- With-extra-charsets = All ### GBK and gbk_chinese_ci can handle Chinese garbled characters
Other settings are optimized for the database, so we will not go into details here.

I have read some msyql5 installation documents and thank you for your reference.
Mysql-5.0.51a.tar.gz after decompression Installation Details:

1 # cd mysql-5.0.51a
2 # mkdir/usr/local/mysql5

(Among the many parameters in this step, the key parameters have been described earlier. If you do not understand them, please refer to the previous introduction .)
3 #./configure
-- Prefix =/usr/local/mysql5
-- Localstatedir =/var/lib/mysql5 -- With-Comment = Source
-- With-server-suffix =-community
-- With-mysqld-user = MySQL
-- Without-Debug
-- With-big-tables
-- With-charset = GBK -- With-collation = gbk_chinese_ci -- With-extra-charsets = all
-- With-pthread
-- Enable-static
-- Enable-thread-safe-Client
-- With-client-ldflags =-all-static
-- With-mysqld-ldflags =-all-static
-- Enable-aggreger
-- Without-InnoDB
-- Without-NDB-Debug
4 # Make
5 # make install

6. # useradd MySQL // Add a MySQL user
7 # cd/usr/local/mysql5
(Note :!!! When installing the second database. /configure is added with -- localstatedir =/var/lib/mysql5, but the mysql5 directory is not generated under/var/lib, therefore, after compiling and installing the source code package, check whether the directory exists. If not, manually create a command: # mkdir/var/lib/mysql5 and then perform Step 8 .)
8 # bin/mysql_install_db -- user = MySQL
(After the seventh step is completed correctly, if this step is executed correctly, corresponding database files will be generated under/var/lib/mysql5 .)
9 # chown-r root: mysql. // set the permission. Note that there is "."
10 # chown-r MySQL/var/lib/mysql5 // set MySQL Directory Permissions
11 # chgrp-r mysql. // note that there is "."
12 # cp share/MySQL/my-huge.cnf/etc/my5.cnf
13 # cp share/MySQL. Server/etc/rc. d/init. d/mysql5 // start MySQL automatically upon startup.
14 # chmod 755/etc/rc. d/init. d/mysql5
15 # chkconfig -- add mysql5

Below 16 are the necessary modifications made to the Startup File mysql5 and configuration file my5.cnf when the second database is installed.
========================================================== ========================================================== ===
/Etc/rc. d/init. d/mysql5

Modify the following content:

1. datadir =/var/lib/mysql5
2. conf =/etc/my5.cnf
3. Replace "$ bindir/mysqld_safe -- datadir = $ datadir -- PID-file = $ server_pid_file $ other_args>/dev/null 2> & 1 &" with (in double quotation marks)
"$ Bindir/mysqld_safe -- defaults-file =/etc/my5.cnf -- datadir = $ datadir -- PID-file = $ server_pid_file $ other_args>/dev/null 2> & 1 &"( in double quotation marks)
========================================================== ========================================================== ===
/Etc/my5.cnf

Modify the following content:

Port = 3307 ### modify the relevant port
Socket file generation path

Change the port numbers in the [client] and [mysqld] To 3307,
Socket =/tmp/MySQL. Sock to socket =/tmp/mysql5.sock
[Client]
# Password = your_password
Port = 3307
Socket =/tmp/mysql5.sock

# Here follows entries for some specific programs

# The MySQL Server
[Mysqld]
Port = 3307
Socket =/tmp/mysql5.sock
========================================================== ========================================================== =
17 #/etc/rc. d/init. d/mysql5 start // start MySQL
18 # bin/mysqladmin-u Root Password "password_for_root" ### set the database JDBC connection password
Note: there are still questions about whether the password is the same as the password used to log on to the database from the client.
Set the password for logging on to the database from the client: (default setting: User name: Root Password: (null ))
19 # cd/usr/local/mysql5/bin (go to the database installation directory and execute the following command)
20 #./MySQL-u root-P (log on to the database and start with mysql> all operations in the database. Do not discard the semicolon.
Mysql> use MySQL;

Mysql> Update user SET Password = PASSWORD ('newpassword') where user = 'root ';
Mysql> flush privileges;
Mysql> exit;
21 # service mysql5 stop // close MySQL

Modification in the 22tomcat deployment file:
Modifying/usr/tomcat/jetmambo/WEB-INF/classes/jdbc. Properties
1.3306 to 3307
2. JDBC. Password = System (note: this password is the password for database JDBC connection)

The modification is as follows:
JDBC. driverclassname = com. MySQL. JDBC. Driver
JDBC. url = JDBC: mysql: // localhost: 3307/timef3_cmd? & Amp; useunicode = true & characterencoding = GBK
JDBC. Username = root
JDBC. Password = System

23. Start the database and web server to verify that the database is successfully installed.
/Etc/init. d/MySQL restart
/Etc/init. d/mysql5 restart
Note: The service must be enabled for both databases. Otherwise, Tomcat reports sqlexception.
/Usr/tomcat/bin/Catalina. Sh run

Note:

In 24linux, the table names in the default database are case-insensitive and are set as follows:
/Etc/my5.cnf

# The MySQL Server
[Mysqld]
Lower_case_table_names = 1 ### 1: case-insensitive 0: case-insensitive
Port = 3307
Socket =/tmp/mysql5.sock

------------------------------------
If you have any questions left over, you can answer them:
Enter
> MySQL
Report:
Error 2002 (hy000): Can't connect to local MySQL server through socket '/var/lib/MySQL. Sock' (2)
Error.
----------------------------------------------------------------
Solved
Http://www.javaeye.com/topic/203986
Thank you very much for this article.

./MySQL-uroot-p-S/tmp/mysql5.sock

If the-S parameter is not added, MySQL. Sock is found in the default directory.

 

Reference: http://www.javaeye.com/topic/203986

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.