Saturday, November 8, 2008

Install MySQL 5.0 on Redhat Linux 8.0

Install MySQL 5.0.x on Redhat Linux
Saturday November 8, 2008


Install RPM package

Uninstall exist RPM package
#rpm -qagrep -i mysql // find out all former installed mysql
Display:
MySQL-server-4.0.12-0
MySQl-client-4.0.12-0
#rpm -e MySQL-server-4.0.12-0
#rpm -e MySQL-client-4.0.12-0

Install new version of MySQL RPM file
#rpm –install MySQL-server-5.0.67-0.i386.rpm
or:
#rpm –ivh MySQL-server-5.0.67-0.i386.rpm


Source (.tar.gz) installation

#groupadd mysql
#useradd –g mysql mysql
(#useradd -M -o -r -d /var/lib/mysql -s /bin/bash -c "MySQL Server" -u 27 mysql )
#cd /usr/local
Download mysql-5.0.51b.tar.gz
#tar -zxvf mysql-5.0.51b
# cd mysql-5.0.51b
# ./configure –prefix=/usr/local/mysql --localstatedir=/var/lib/mysql

***./configure --prefix=/usr/local/mysql
--sysconfdir=/etc // path for file my.ini
--localstatedir=/var/lib/mysql //path to the data folder

--without-debug \not debug mode
--with-extra-charsets=gb2312 \ add gb2312 Chinese characters support
--enable-assembler \ use character function's assmbler
--without-isam \ no support for isam table, isam tables are plateform dependent table
--without-innodb \no support for innodb table, innodb tables are the tables support transaction, usually for enterprise use
--with-pthread \ force to use pthread library(posix pthread library)
--enable-thread-safe-client \Compile terminal by using thread mode
--with-client-ldflags=-all-static \ --with-mysqld-ldflags=-all-static \ Compile Server and Client site by using static mode

# make
# make install

# cd /usr/local/mysql
# cp share/mysql/my-medium.cnf /etc/my.cnf
Or
# cp support-files/my-medium.cnf /etc/my.cnf \copy configure file,there are large,medium,small three enviornments. select based on the performence, when load is havey,change the variable in the configure file to change the memory size used by MySQL

# bin/mysql_install_db --user=mysql (# scripts/mysql_install_db \Create mysql user Database and table files )
# chown -R root:mysql /usr/local/mysql
(# chmod 750 mysql -R )
# chgrp -R mysql . (# chgrp -R mysql /usr/local/mysql)

# chown –R mysql:mysql /var/lib/mysql
# chmod 777 /var/lib/mysql

Start MySQL
# bin/mysqld_safe --user=mysql & (It is important to start MySQl by user mysql.)
# bin/mysql -uroot -p (type password, the default password is empty,so just type enter.)

# Can't connect to local MySQL server through socket '/tmp/mysql.sock'

If the above message displayed, mysql server does not start. mysql will be able create mysql.sock file if mysql server start normally.


# killall mysql !!!!! will kill all mysqk process

Restart
# /bin/mysqld_safe --user=mysql &
# bin/mysql -uroot -p

- start mysql
# /bin/mysqld_safe --user=mysql &
or
# /usr/local/mysql/share/mysql/mysqld start

-stop mysql
/usr/local/bin/mysqladmin shutdown

Add password for root:
# mysqladmin –u root password "youpassword" // set the password for the root account
# mysql -uroot -p
enter your password, get into mysql
mysql>use mysql;
mysql>delete from user where password=""; //delete the account with out password, which is used for local anonymous to connect to mysql DB
mysql>flush privileges;
mysql>quit


To start mysql automatically when Linux starts up

# cp shared/mysql/mysql.server /etc/rc.d/init.d/mysqld
(# cp support-files/mysql.server /etc/init.d/mysqld \copy mysqld
# chmod 700 /etc/init.d/mysqld)
(chmod a+x /usr/local/mysql/share/mysql/mysqld)

# chkconfig –add mysqld
# chkconfig --level 345 mysqld on
# service mysqld start
?(# netstat -atln )
??? use “ntsysv” to set up mysql start when every time the Linux starts

MySQL installation completed.

To start mysql service
/etc/rc.d/init.d/mysqld start


Troubleshooting

1. Dealing with problems compileing MySQL

If configure is run after it has previously been run, it may use information that was gathered during its previous invocation. This information is stored in config.cache. When configure starts up, it looks for that file and reads its contents if it exists, on the assumption that the information is still correct. That assumption is invalid when you reconfigure.
Each time you run configure, you must run make again to recompile. However, you may want to remove old object files from previous builds first because they were compiled using different configuration options.
To prevent old configuration information or object files from being used, run these commands before re-running configure:
shell> rm config.cache
shell> make clean


2. Check config.log file can see the information loged while config.

If you get the error message:
ERROR 2002: Can't connect to local MySQL server through socket /var/lib/mysql/mysql.sock' (2)
Check error log: /var/lib/mysql/*.err
You will find why mysql can’t start,the reason is the permission of the folder /var/lib/mysql does not allow user mysql to access.
Mysql is started by the user mysql by default. Now we know the reason (mysql can’t start),
What we need to do is:
# chown -R mysql:mysql /var/lib/mysql
Or you can set up the permission by using the following commands:

#chown -R root /usr/local/mysql
#chgrp -R mysql /usr/local/mysql
#chown -R root /usr/local/mysql/bin
#chgrp -R mysql /usr/local/mysql/bin
#chgrp -R mysql /var/lib/mysql
#chmod 777 /var/lib/mysql
#chown -R root /var/lib/mysql/mysql
#chgrp -R mysql /var/lib/mysql/mysql
#chmod 777 /var/lib/mysql/mysql
#chown -R root /var/lib/mysql/mysql/*
#chgrp -R mysql /var/lib/mysql/mysql/*
#chmod 777 /var/lib/mysql/mysql/*
#chmod 777 /usr/local/mysql/lib/mysql/libmysqlclient.a

3. If you get the following error message:
Can't start server: Bind on TCP/IP port: Invalid argument071207 22:50:57 [ERROR] Do you already have another mysqld server running on port: 3306 ?071207 22:50:57 [ERROR] Aborting071207 22:50:57 [Note] mysqld-max-nt: Shutdown complete

Try this command to shutdown mysql
#mysqladmin --host=abc --password shutdown


MySQL command used frequently

??mysqld -----start log support --log --log-update --log-long-formart

Created a new user and grant all the privileges to operate the database
mysql> grant all on database.* to user identified by "password"

revoke all on database from user

revoke all privileges on the database

Run the sql command in the file.sql in the databasename
mysql -uroot -p --one-database databasename < file.sql

Let mysqld to open a new log file, to clean the old log file
mysqladmin mysqladmin flush-logs

To link mysql’s lib and include path to default path (you don’t have to), use the lines:
ln -s /usr/local/mysql/lib/mysql /usr/lib/mysql
ln -s /usr/local/mysql/include/mysql /usr/include/mysql

No comments: