Installation, optimization, and security configuration of MySQL 5.1.x in CentOS Linux
Download Page: http://dev.mysql.com/downloads/mysql/5.1.html#downloads
Groupadd mysql
Create a user group named mysql
Useradd-g mysql
Create a user named mysql under the mysql user group
Gunzip | mysql-VERSION.tar.gz | tar-xvf-
Decompress the downloaded .gz File
Cd mysql-VERSION
Enter the decompressed directory
CFLAGS = "-O3-mcpu = pentium4" CXX = gcc CXXFLAGS = "-O3-march = pentium4-felide-constructors-fno-exceptions-fno-rtti ″. /configure-prefix =/home/mysql/-without-debug-with-unix-socket-path =/home/mysql/tmp/mysql. sock-with-client-ldflags =-all-static-with-mysqld-ldflags =-all-static-enable-encryption er-with-extra-charsets = gbk, gb2312, utf8-without-innodb-without-isam-with-pthread-enable-thread-safe-client
Configure mysql
Gcc parameters:
-O3
-O
-O1
Optimization. For large functions, optimizing compilation takes a little more time and a considerable amount of memory.
Without the '-O' option, the compiler aims to reduce compilation overhead and enable debugging of compilation results. the statement is independent: If you stop a program with a breakpoint between two statements, you can assign a value to any variable, or point the program counter to another statement in the function body, and precisely obtain the expected results from the source program.
When the '-O' option is not used, only the variables declared with register are allocated with registers. The compilation result is slightly inferior to those without the'-O' option.
With the '-O' option, the compiler will try to reduce the size and execution time of the target code.
If the '-O' option is specified, the'-fthread-jumps 'and'-fdefer-pop' options are enabled. the '-fdelayed-branch' option is enabled on a machine with a delay slot. on a machine that supports debugging even if there is no frame pointer (frame pointer), the '-fomit-frame-pointer' option is enabled. other options may be enabled on some machines.
-O2
More optimizations. in addition to optimization options that involve space and speed switching, almost all optimization work is performed. for example, loop unrolling and inlining are not performed ). compared with the-O option, this option increases both the Compilation Time and the running effect of the generated code.
-O3
More optimizations. Apart from opening what-O2 does, it also opens the-finline-functions option.
-O0
Not optimized.
If multiple-O options are specified, the last option takes effect regardless of the number.
-Mcpu = pentium4 optimized compilation based on the CPU type, which can make your mysq performance better! Optional item lot: i386, i386, i586, i686, pentium, pentium-mmx, pentiumpro, pentium2, pentium3, pentium4, k6, k6-2, athlon, athlon-tbird, k6-3, athlon-xp, athlon-mp, winchip-c6, winchip2, c3.
-Fomit-frame-pointer does not store pointers in registers for functions that do not require a stack pointer. Therefore, you can ignore the code for storing and retrieving addresses and use registers for common purposes. One option is enabled for all "-O" levels, but it is valid only when the debugger can run without relying on the stack pointer. We recommend that you set it explicitly without debugging.
Configure parameters:
-Prefix =/home/mysql/Specify the installation directory
-Remove debug mode from without-debug
-With-extra-charsets = gbk, gb2312, and utf8 are supported by adding gbk, gb2312, and utf8 Chinese Characters
-With-pthread enforces the use of the pthread Library (posix thread Library)
-Enable-aggreger uses the assembly version of some character functions.
-Enable-thread-safe-client: Compile the client in thread mode
-With-client-ldflags =-all-static compile the client in pure static mode
-With-mysqld-ldflags =-all-static compile server in pure static mode
-Without-isam removes the isam table type and is rarely used now. The isam table is a platform-dependent table.
-Without-innodb removes innodb table support. innodb is a table that supports transaction processing and is suitable for enterprise-level applications.
Make
Compile
Make install
Install
Cp support-files/my-medium.cnf/etc/my. cnf
Copy the mysql configuration file to the/etc directory and rename it my. cnf
/Home/mysql has 5 my-xxxx.cnf files below
My-small.cnf minimum configuration installation, memory <= 64 M, minimum data
My-large.cnf memory = 512 M
My-medium.cnf 32 M <memory <64 M, or memory 128 M, but the database and web server public memory
My-huge.cnf 1G <memory <2G, the server mainly runs mysql
My-innodb-heavy-4G.cnf Max configuration installation with at least 4 GB memory
Cd/home/mysql
Go to the installation directory
Bin/mysql_install_db-user = mysql
Create a data table as a mysql user
Chown-R root.
Set the owner of the mysql home directory (that is,/home/mysql) as the root user. This is a command in the official document, but it is strange that if you set the main directory owner of mysql as a root user, mysql cannot be started after running bin/mysqld_safe-user = mysql. The problem lies in "permission". Run chown-R mysql. You can run the following command to start mysql normally. Is the official document incorrect? I hope you will discuss it together.
Chown-R mysql var
Set the owner of the var directory to a mysql user
Chgrp-R mysql.
Set the owner of the mysql main directory to the mysql user group (Note: Unlike the previous command, this command authorizes the user group)
Bin/mysqld_safe-user = mysql &
Start mysql. If everything is normal, no prompt will be displayed after running this command.
Bin/mysqladmin-u root password
Modify the password of the root user. Here, the root user refers to the root user of mysql, which has nothing to do with the root user of Linux. The green password is the new password you need to set. Remember!
Bin/mysql-u root-p
If it is normal, you can log on with this name. After you enter the password, the prompt "mysql>" appears, indicating that the logon is successful. Exit with the quit command
Run the following command to set mysql to run automatically upon startup:
Cd mysql-VERSION
Enter the decompressed directory again, that is, the source code directory.
Cp support-files/mysql. server/etc/init. d/mysql
Copy the mysql. server File to the/etc/init. d/directory and rename it mysql.
Chmod 755/etc/init. d/mysql
Grant the "execution" permission to the/etc/init. d/mysql file.
Chkconfig-level 345 mysql on
Added to Automatic startup, with a running level of 3 4 5
Service mysql restart
Restart mysql Service
Q: Why do I prompt "connect fail: Can't connect to local Mysql server through socket '/home/MySQL/tmp/mysql. sock' (13)" When I connect to mysql using PHP )"
A: This is because PHP cannot normally connect to the Mysql socket, that is, the mysql. sock file. First, check whether the mysql. sock file exists in the/home/mysql/tmp/directory. If not, it may be that mysql is not started properly; If yes, it may be that the permission for the/home/mysql/tmp/directory is insufficient, use chmod 755/home/mysql/tmp to solve this problem.