Check: Remove the original M Ysql
Because MySQL database is very popular on Linux, so the mainstream Linux version of the current download basically integrates the MySQL database inside, we can use the following command to see if the MySQL database is installed on our operating system
[[Email protected] ~] # rpm-qa | grep mysql #这个命令就会查看该操作系统上是否已经安装了mysql数据库
If there is, we can unload it by RPM-E command or rpm-e--nodeps command.
[[Email protected] ~] # rpm-e MySQL #普通删除模式[[email protected] ~]# rpm-e--nodeps mysql #强力删除模式, if you use the above command to delete, prompt to have dependencies on its It can be forcefully deleted with this command.
After the deletion we can pass Rpm-qa | grep mysql command to see if MySQL has been uninstalled successfully!
first, compile and install MySQL Pre-preparatory work
1. Install the tools and libraries needed to compile the source code.
2, install CMake, download the source code from http://www.cmake.org and compile the installation
wget http://www.cmake.org/files/v2.8/cmake-2.8.10.2-xzvf cmake-2.8.10.2. TAR.GZCD cmake-2.8.10.2 . /bootstrap; make; Make install
Second, set MySQL Users and Groups
1. New MySQL user group
Groupadd MySQL
2. New MySQL User
Useradd-r-G MySQL MySQL
third, the new MySQL The directory you need
1. New MySQL installation directory
Mkdir-p/usr/local/mysql
2. New MySQL database data file directory
Mkdir-p/data/mysqldb
Download the MySQL source package and unzip it.
Download the source code directly from http://dev.mysql.com/downloads/mysql/
wget http://www.kakapart.com/files/mysql-5.6.16 tar.gz-F mysql-5.6.16. tar.gz CD MySQL-5.6.16
v. Compile and install MySQL
1, from mysql5.5, MySQL source installation started using CMake, set the source code compilation configuration script.
cmake \ -dcmake_install_prefix=/usr/local/mysql \ -dmysql_unix_addr=/usr/local/mysql/mysql.sock \ -ddefault_charset=UTF8 \ -ddefault_collation=utf8_general_ci \ -dwith_innobase_ Storage_engine=1 \ -dwith_archive_storage_engine=1 \ -dwith_blackhole_storage_ Engine=1 \ -dmysql_datadir=/data/mysqldb \ -dmysql_tcp_port=3306 \ -denable_downloads=1
-dcmake_install_prefix=dir_name |
Setting up the MySQL installation directory |
-dmysql_unix_addr=file_name |
Set the listener socket path, which must be an absolute pathname. Default is/tmp/mysql.sock |
-ddefault_charset=charset_name |
Sets the character set of the server. By default, MySQL uses the latin1 (CP1252 Western European) character set. The Cmake/character_sets.cmake file contains a list of allowed character set names. |
-ddefault_collation=collation_name |
Sets the collation of the server. |
-dwith_innobase_storage_engine=1 -dwith_archive_storage_engine=1 -dwith_blackhole_storage_engine=1 -dwith_perfschema_storage_engine=1 |
Storage Engine Options: Myisam,merge,memory, and the CSV engine is compiled to the server by default and does not need to be explicitly installed. Statically compiles a storage engine to the server, using-dwith_engine_storage_engine= 1 The available storage engine values are: ARCHIVE, Blackhole, EXAMPLE, Federated, Innobase (InnoDB), PARTITION (partitioning support), and Perfschema ( Performance Schema) |
-dmysql_datadir=dir_name |
Set the MySQL database file directory |
-dmysql_tcp_port=port_num |
Set the MySQL server listening port, default to 3306 |
-denable_downloads=bool |
Whether you want to download the optional files. For example, if you enable this option (set to 1), CMake will download the test suite that Google uses to run unit tests. |
Note: To rerun the configuration, you need to delete the CMakeCache.txt file
RM CMakeCache.txt
2. Compiling the source code
Make
3. Installation
Make install
Vi. modifying MySQL directory Owners and Groups
1. Modify the MySQL installation directory
cd/usr/local/MySQL -r mysql:mysql. # Note the following decimal point, which indicates the current directory, cannot be omitted.
2. Modify the MySQL database file directory
cd/data/mysqldb -R mysql:mysql. # note the decimal point behind
Vii. Initialization MySQL Database
cd/usr/local/mysql scripts/mysql_install_db--user=mysql--datadir=/data/mysqldb
Viii. Reproduction MySQL Service startup configuration file
cp/usr/local/mysql/support-files/my-default. cnf/etc/my.cnf # Note: if/etc/ MY.CNF file exists then overwrite
Nine, copy MySQL service startup scripts and joins PATH Path
CP support-files/mysql.server/etc/init.d//etc/profile export PATH=/usr/local/mysql/bin:/ Usr/local/mysql/lib:$PATH /etc/profile # takes effect with environment variables
X. Start the MySQL service and join the boot-up
--level mysqld on
Xi. Check if the MySQL service is started
NETSTAT-TULNP | grep 3306 -u root-p #
12. Modification MySQL User Root the password
mysqladmin-u root password ' 123456 '
Note: You can also run the security settings script, modify the password of the MySQL user root, and disable the root remote connection, remove the test database and anonymous users.
/usr/local/mysql/bin/mysql_secure_installation
13. Errors that may occur
Problem: Starting MySQL. The server quit without updating PID file ([failed]/mysql/server03.mylinux.com.pid).
FIX: Modify/etc/my.cnf in DataDir, point to correct MySQL database file directory
Issue: ERROR 2002 (HY000): Can ' t connect to local MySQL server through socket '/tmp/mysql.sock ' (2)
Workaround: Create a new link or add the-s parameter to MySQL to directly indicate the Mysql.sock location.
Ln-s/usr/local/mysql/data/mysql.sock/tmp/mysql.sock /usr/local/mysql/bin/mysql-u root-s/usr/local/ Mysql/data/mysql.sock
Problem:-bash:mysql:command not found
FIX: Because the path of the MySQL command is under/usr/local/mysql/bin, so when you use the MySQL command directly, the system checks the command under/usr/bin, so I can't find it.
Make a link:
Ln-s/usr/local/mysql/bin/mysql/usr/bin
--Solemn statement: This article is only for the author's personal notes, please do not reprint! ——
Linux CentOS6.5 under compile and install MySQL 5.6