Centos6.5 install mysql5.5

wrote
The installation method is divided into rpm and source code compilation and installation. This article uses the mysql source code compilation method, and the compiler uses Cmake. The software requires mysql-5.5.29.tar.gz and cmake-2.8.10.2.tar.gz, please download by yourself.
Download address:
http://mysql.mirror.kangaroot.net/Downloads/MySQL-5.5/
http://www.cmake.org/files/v2.8/cmake-2.8.10.2.tar.gz
where mysql uses the latest The stable version, that is, the previous version of the latest trial version, and the non-rc or alpha version, the latest version directly used by Cmake.
1. Upload mysql-5.5.29.tar.gz and cmake-2.8.10.2.tar.gz to the /usr/local folder.
2. CentOS install g++ and ncurses-devel
[root@fiona local]# yum install gcc-c++
[root@fiona local]# yum install ncurses-devel
3.cmake installation
[root@fiona local]# nohup wget http:/ /www.cmake.org/files/v2.8/cmake-2.8.10.2.tar.gz &
[root@fiona src]# tar -zxv -f cmake-2.8.10.2.tar.gz
[root@fiona src] # cd cmake-2.8.10.2
[root@fiona cmake-2.8.10.2]# ./configure
[root@fiona cmake-2.8.10.2]# make
[root@fiona cmake-2.8.10.2]# make install
4. Permanently add cmake to the system environment variable
using vi Add the variable in the file /etc/profile to make it permanent,
[root@fiona cmake-2.8.10.2]# vi /etc/profile
Append the following two lines of code at the end of the file:
PATH=/usr/local/cmake- 2.8.10.2/bin:$PATH
export PATH
Execute the following code to make the modification take effect:
[root@fiona cmake-2.8.10.2]# source /etc/profile
Use the export command to view the PATH value
[root@fiona cmake-2.8.10.2 ]# echo $PATH
5. Create mysql installation directory and database storage directory
[root@fiona local]# mkdir -p /usr/local/mysql //Install mysql
[root@fiona local]# mkdir -p /usr/local /mysql/data //Store database
6. Create mysql user and user group
[root@fiona local] groupadd mysql
[root@fiona local]useradd -r -g mysql mysql

7.编译安装mysql
[root@fiona src]# nohup wget http://cdn.mysql.com/Downloads/MySQL-5.5/mysql-5.5.39.tar.gz & //mysql-5.5.39此版本已无
[root@fiona src]# tar zxvf mysql-5.5.39.tar.gz //解压
[root@fiona src]# cd mysql-5.5.29
[root@fiona mysql-5.5.39]#
cmake -DCMAKE_INSTALL_PREFIX=/usr/local/mysql \
-DMYSQL_UNIX_ADDR=/usr/local/mysql/mysql.sock \
-DDEFAULT_CHARSET=utf8 \
-DDEFAULT_COLLATION=utf8_general_ci \
-DWITH_MYISAM_STORAGE_ENGINE=1 \
-DWITH_INNOBASE_STORAGE_ENGINE=1 \
-DWITH_MEMORY_STORAGE_ENGINE=1 \
-DWITH_READLINE=1 \
-DENABLED_LOCAL_INFILE=1 \
-DMYSQL_DATADIR=/usr/local/mysql/data \
-DMYSQL_USER=mysql \
-DMYSQL_TCP_PORT=3306
[root@fiona mysql-5.5.39]# make
[root@fiona mysql-5.5.39]# make install
8. Verify that the installation is successful
[root@fiona mysql-5.5.39] # cd /usr/local/mysql
[root@fiona mysql]# ls
bin data include lib mysql-test scripts sql-bench
COPYING docs INSTALL-BINARY man README share support-files
If you have bin and other files above, congratulations on your successful installation mysql.
Configure mysql
9. Set mysql directory permissions
[root@fiona mysql]# cd /usr/local/mysql //Set the owner of all files in the current directory to root, and the group to which they belong is mysql
[root@fiona mysql]# chown - R root:mysql .
[root@fiona mysql]# chown -R mysql:mysql data
10. Add the mysql startup service to the system service
[root@fiona mysql]# cp support-files/my-medium.cnf /etc /my.cnf
cp: Overwrite "/etc/my.cnf"? y
11. Create system database tables
[root@fiona mysql]# cd /usr/local/mysql
[root@fiona mysql]# scripts/mysql_install_db --user=mysql
12. Set environment variables
[root@fiona mysql]# vi /root/.bash_profile
is modifying PATH=$PATH:$HOME/bin to:
PATH=$PATH:$HOME/bin:/usr/local/mysql/bin:/usr/local/mysql/lib
[root@fiona mysql ]# source /root/.bash_profile //Make the changes just now take effect
13. Manually start mysql
[root@fiona mysql]# ./bin/mysqld_safe --user=mysql & //Start MySQL, but not stop
mysqladmin -u root -p shutdown //At this time, root does not have a password, so it is a null value. When prompted to enter a password, just press Enter.
14. Add the mysql startup service to the system service
[root@fiona mysql]# cp support-files/mysql.server /etc/init.d/mysql
15. Start mysql
[root@fiona mysql]# service mysql start
Starting MySQL... ERROR! The server quit without updating PID file (/usr/local/mysql/data/localhost.localdomain.pid).
Startup failed:
I have a permission problem here, first change the permission
[root@fiona mysql]# chown -R mysql:mysql /usr/local/mysql
Then start the server
[root@fiona mysql]# /etc/init.d/mysql start
Note:
MySQL startup method
1) Call mysqld directly. This is the least common way and is not recommended.
2) Run the mysql.server script
The mysql.server script starts the server by calling mysqld_safe. The script can specify whether to start or shut down through the parameters start and stop.
The mysql.server script is in the share/mysql directory under the MySQL installation directory. If MySQL is installed from source code, it can be found in the support-files directory. If you want to use mysql.server, you must copy it to the appropriate runlevel directory as follows:
1
2
3
4
5
6
7
8
9
10
11
12
13
cp mysql.server /etc/init.d/mysqld
chmod 755 /etc/init.d/mysqld
After the above configuration, you can use the following commands to start and stop the MySQL instance:
service mysqld start/stop
/etc/init. d/mysqld start/stop
Use the chkconfig command to configure automatic startup at boot:
[sql]
chkconfig --add mysqld
chkconfig mysqld on
Run the following command to check whether it is enabled correctly:
[plain]
[root@data data]# chkconfig --list mysqld
mysqld 0 :off 1:off 2:on 3:on 4:on 5:on 6:off MySQL shutdown mode
1
<span style="white-space:normal;">mysqladmin -p -u root shutdown </span>
1
2
3
Processes running in the background after startup
root 2294 1 0 03:53 pts/1 00:00:00 /bin/sh /usr/local/mysql/bin/mysqld_safe --datadir=/usr/local/mysql/data --pid-file=/usr/ local/mysql/data/fiona.pid
mysql 2595 2294 0 03:53 pts/1 00:00:00 /usr/local/mysql/bin/mysqld --basedir=/usr/local/mysql --datadir=/usr /local/mysql/data --plugin-dir=/usr/local/mysql/lib/plugin --user=mysql --log-error=/usr/local/mysql/data/fiona.err --pid-file =/usr/local/mysql/data/fiona.pid --socket=/usr/local/mysql/mysql.sock --port=3306
16. Modify the password of the MySQL root user and open a remote connection
[root@localhost mysql ]# mysql -u root mysql
mysql> use mysql;
mysql> desc user;
mysql> GRANT ALL PRIVILEGES ON *.* TO root@"%" IDENTIFIED BY "root"; //Add the ability to connect remotely to root
mysql> update user set Password = password('abc123' ) where User='root'; //Set the root user password
mysql> select Host,User,Password from user where User='root';
mysql> flush privileges;
mysql> exit
17. Re-login
[root@localhost mysql]# mysql -u root -p
Enter password:
abc123 Remote connection, close the firewall
[root@localhost]# /etc/rc.d/init.d/iptables stop

18. Configure Innodb
[root@fiona plugin]# cd /etc
[root@fiona etc]# vi my.cnf
# To take best advantage of current InnoDB features
innodb_file_per_table=1
innodb_file_format=barracuda
innodb_strict_mode=1
//Official recommendation

19. Database shutdown
[root@fiona mysql]# /usr/local/mysql/support-files/mysql.server stop
Shutting down MySQL. SUCCESS!

Error when starting Mysql:
140907 14:04:09 mysqld_safe Logging to '/usr/local/mysql/data/fiona.err'.
140907 14:04:09 mysqld_safe Starting mysqld daemon with databases from /usr/local/mysql/data
140907 14:04: 11 mysqld_safe mysqld from pid file /usr/local/mysql/data/fiona.pid ended
because the following command was used to log in:
shell> ./bin/mysqld_safe --user=root &
cause to use
shell> ./bin/ when logging in again mysqld_safe --user=mysql &
Solution: Initialize mysql
/usr/local/mysql/scripts/mysql_install_db --user=mysql

1. #service mysqld start
prompt: mysqld unrecognized service
Reason : mysql-server
is not installed Solution : install mysql-server
yum installation: #yum -y install mysql-server
rpm package required to install mysql:
mysql-5.1.61-1.el6_2.1.i686.rpm
mysql-server-5.1.61-1.el6_2.1.i686.rpm
mysql-libs-5.1.61-1.el6_2.1.i686.rpm

2. #mysql -u root -p passwd
prompt: ERROR 2002 (HY000 ): Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2)
Reason: mysqld service is not
enabled Solution: switch to root and enable mysqld service
Command: #service mysqld start

3 , Check the mysql installation path
Command : #whereis mysql

4. Check whether the mysqld service has been added to the linux
Command: #chkconfig --list mysqld
has been added Prompt: mysql 0: close 1: close 2: close 3: close 4: close 5: Enable 6: Disable

5. When the mysqld service is enabled, check whether the server is running
Command : ps -ef | grep mysqld

Reference:
http://dev.mysql.com/doc/refman/5.5/en/binary-installation.html
http ://www.cnblogs.com/zhoulf/archive/2013/01/25/zhoulf.html
Four ways to start mysql (mysql_safe is recommended)
http://blog.chinaunix.net/uid-13642598-id-3153537.html
mysql DBA: Summary of mysqladmin common commands
http://www.jb51.net/article/48169. htm#
http://www.linuxidc.com/Linux/2011-03/33362.htm

Instructions for compiling and installing mysql and mysql mysqladmin tool
http://www.it165.net/database/html/201404/5890 .html
The listening port of mysql is 3306
[root@fiona2 bin]# ss -tnl
State Recv-Q Send-Q Local Address:Port Peer Address:Port
LISTEN 0 128 *:37677 *:*
LISTEN 0 128 :::111 : ::*
LISTEN 0 128 *:111 *:*
LISTEN 0 128 :::22 :::*
LISTEN 0 128 *:22 *:*
LISTEN 0 128 127.0.0.1:631 *:*
LISTEN 0 128 ::1: 631:::*
LISTEN 0 128:::19419:::*
LISTEN 0 50 *:3306 *:*

[root@fiona2 bin]# mysqladmin -uroot -p processlist
+----+------+-----------+--- -+---------+------+-------+------------------+
| Id | User | Host | db | Command | Time | State | Info |
+----+------+-------------+----+------- --+------+-------+------------------+
| 7 | root | localhost | | Query | 0 | | show processlist |
+----+------+-----------+----+---------+------+ -------+------------------+

======================== ===========================
[root@fiona home]# su - mysql
su: warning: cannot switch to directory /home/mysql : No such file or directory

# cp -rfv /etc/skel/.* /home/mysql
# chown -Rv mysql.mysql /home/mysql

solution to bash: mysql: command not found
Reason: This is because the system will look for the command under /usr/bin by default. If the command is not in this directory, of course, the command will not be found. What we need to do is to map a link to the /usr/bin directory, which is equivalent to Create a link file.
First of all, you need to know the full path of the mysql command or mysqladmin command. For example, the path of mysql is: /usr/local/mysql/bin/mysql, we can execute the command like this:
# ln -s /usr/local/mysql/bin/mysql /usr/bin

 

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=326833641&siteId=291194637