Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to install MYSQL with source code

2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >

Share

Shulou(Shulou.com)05/31 Report--

This article mainly introduces "how to install MYSQL with source code". In daily operation, I believe many people have doubts about how to install MYSQL with source code. The editor consulted all kinds of materials and sorted out simple and easy-to-use methods of operation. I hope it will be helpful to answer the doubts of "how to install MYSQL with source code". Next, please follow the editor to study!

I. description of the article

Recently came into contact with the mysql database, so spare no time to study, today to demonstrate the use of source code to install mysql, if you use the rpm package to install, then the personal feeling is quite simple.

Environment description:

Operating system: rhel 5.4x86

Mysql version: mysql-5.5.22

Second, install cmake (mysql5.5 is later compiled through cmake)

You can edit directly before mysql5.5, but you need to compile through cmake after 5.5. direct compilation is introduced in the appendix.

Download cmake-2.8.4.tar.gz, I search in du Niang.

[root@node4 ~] # tar-zxvf cmake-2.8.4.tar.gz [root@node4 ~] # cd cmake-2.8.4 [root@node4 cmake-2.8.4] #. / configure-- prefix=/usr/local/cmake-you can use # gmake & & make install [root@node4 cmake-2.8.4] # make [root@node4 cmake-2.8.4] # make install here

Note: configure needs to perform compilation to a directory.

Create the installation directory and database storage directory of mysql

[root@node4] # mkdir-p / opt/mysql5.5 [root@node4 ~] # mkdir-p / opt/mysql5.5/data

Create mysql users and user groups

[root@node4 ~] # groupadd mysql [root@node4 ~] # useradd-r-g mysql mysql

5. Install mysql

[root@node4 ~] # tar-zxvf mysql-5.5.22.tar.gz [root@node4 ~] # cd mysql-5.5.22-the following error occurred in compilation Need ncurses-devel [root@node4 mysql-5.5.22] # / usr/local/cmake/bin/cmake-DCMAKE_INSTALL_PREFIX=/opt/mysql5.5-DMYSQL_DATADIR=/opt/mysql5.5/data-DDEFAULT_CHARSET=utf8-DDEFAULT_COLLATION=utf8_general_ci-DEXTRA_CHARSETS=all-DENABLED_LOCAL_INFILE=1-- MySQL 5.5.22-- Could NOT find Curses (missing: CURSES_LIBRARY CURSES_INCLUDE_PATH) CMake Error at cmake/readline.cmake:83 (MESSAGE): Curses library not found. Please install appropriate package, remove CMakeCache.txt and rerun cmake.On Debian/Ubuntu, package name is libncurses5-dev, on Redhat and derivates it is ncurses-devel.Call Stack (most recent call first): cmake/readline.cmake:127 (FIND_CURSES) cmake/readline.cmake:217 (MYSQL_USE_BUNDLED_LIBEDIT) CMakeLists.txt:268 (MYSQL_CHECK_READLINE)-- Configuring incomplete Errors occurred!-check whether ncurses is installed: [root@node4 mysql-5.5.22] # rpm-qa | grep necursesncurses-5.5-24.20060715-install ncurses-devel [root@node4] # rpm-ivh ncurses-devel-5.5-24.20060715.i386.rpm warning: ncurses-devel-5.5-24.20060715.i386.rpm: Header V3 DSA signature: NOKEY, key ID 37017186 Preparing... # [100%] 1:ncurses-devel # [100%]-delete CMakeCache.txt [root@node4 Mysql-5.5.22] # find /-name CMakeCache.txt / root/mysql-5.5.22/CMakeCache.txt / root/cmake-2.8.4/CMakeCache.txt / root/cmake-2.8.4/Tests/ComplexOneConfig/Cache/CMakeCache.txt / root/cmake-2.8.4/Tests/Complex/Cache/CMakeCache.txt / root/cmake-2.8.4/Tests/CMakeFiles/CheckFortran/CMakeCache.txt / root/cmake-2.8.4/Tests/ComplexRelativePaths/ Cache/CMakeCache.txt [root@node4 mysql-5.5.22] # rm / root/mysql-5.5.22/CMakeCache.txtrm: remove regular file `/ root/mysql-5.5.22/CMakeCache.txt'? Yes [root@node4 mysql-5.5.22] # rm / root/cmake-2.8.4/CMakeCache.txtrm: remove regular file `/ root/cmake-2.8.4/CMakeCache.txt'? Yes [root@node4 mysql-5.5.22] # rm / root/cmake-2.8.4/Tests/ComplexOneConfig/Cache/CMakeCache.txtrm: remove regular file `/ root/cmake-2.8.4/Tests/ComplexOneConfig/Cache/CMakeCache.txt'? Yes [root@node4 mysql-5.5.22] # rm / root/cmake-2.8.4/Tests/Complex/Cache/CMakeCache.txtrm: remove regular file `/ root/cmake-2.8.4/Tests/Complex/Cache/CMakeCache.txt'? Yes [root@node4 mysql-5.5.22] # rm / root/cmake-2.8.4/Tests/CMakeFiles/CheckFortran/CMakeCache.txtrm: remove regular file `/ root/cmake-2.8.4/Tests/CMakeFiles/CheckFortran/CMakeCache.txt'? Yes [root@node4 mysql-5.5.22] # rm / root/cmake-2.8.4/Tests/ComplexRelativePaths/Cache/CMakeCache.txtrm: remove regular file `/ root/cmake-2.8.4/Tests/ComplexRelativePaths/Cache/CMakeCache.txt'? Yes-compile again: [root@node4 mysql-5.5.22] # / usr/local/cmake/bin/cmake-DCMAKE_INSTALL_PREFIX=/opt/mysql5.5-DMYSQL_DATADIR=/opt/mysql5.5/data-DDEFAULT_CHARSET=utf8-DDEFAULT_COLLATION=utf8_general_ci-DEXTRA_CHARSETS=all-DENABLED_LOCAL_INFILE=1 [root@node4 mysql-5.5.22] # make & & make install

Note:

-DCMAKE_INSTALL_PREFIX=/usr/local/mysql / / installation directory

-DINSTALL_DATADIR=/usr/local/mysql/data / / database storage directory

-DDEFAULT_CHARSET=utf8 / / use utf8 characters

-DDEFAULT_COLLATION=utf8_general_ci / / check character

-DEXTRA_CHARSETS=all / / install all extended character sets

-DENABLED_LOCAL_INFILE=1 / / allow data to be imported locally

Note:

When recompiling, you need to clear the old object files and cache information.

# make clean

# rm-f CMakeCache.txt

# rm-rf / etc/my.cnf

VI. Set directory permissions

[root@node4] # cd / opt/mysql5.5/ [root@node4 mysql5.5] # chown-R root:mysql. / / set the owner of all files in the current directory to root and the group to which they belong is mysql [root@node4 mysql5.5] # chown-R mysql:mysql data/

7. Set up mysql configuration file

[root@node4 mysql5.5] # cp support-files/my-medium.cnf / etc/my.cnf / / add the startup service of mysql to the system service [root@node4 mysql5.5] # cp support-files/my-medium.cnf my.cnf [root@node4 mysql5.5] # more my.cnf-add basedir = / opt/mysql5.5 datadir = / opt/mysql5.5/data [mysqld] port = 3306 socket = / tmp/mysql under mysqld .sockskip-external-lockingkey_buffer_size = 16Mmax_allowed_packet = 1Mtable_open_cache = 64 sort_buffer_size = 512Knet_buffer_length = 8Kread_buffer_size = 256Kread_rnd_buffer_size = 512Kmyisam_sort_buffer_size = 8Mbasedir = / opt/mysql5.5 datadir = / opt/mysql5.5/data

Create the table of the system database

-specify the configuration file and user [root@node4 mysql5.5] # scripts/mysql_install_db-- defaults-file=./my.cnf-- user=mysql Installing MySQL system tables...OKFilling help tables...OK To start mysqld at boot time you have to copysupport-files/mysql.server to the right place for your systemPLEASE REMEMBER TO SET A PASSWORD FOR THE MySQL root USER! To do so, start the server, then issue the following commands: / opt/mysql5.5/bin/mysqladmin-u root password' new-password' / opt/mysql5.5/bin/mysqladmin-u root-h node4 password' new-password' Alternatively you can run: / opt/mysql5.5/bin/mysql_secure_installationwhich will also give you the option of removing the testdatabases and anonymous user created by default. This is strongly recommended for production servers.See the manual for more instructions.You can start the MySQL daemon with:cd / opt/mysql5.5; / opt/mysql5.5/bin/mysqld_safe & You can test the MySQL daemon with mysql-test-run.plcd / opt/mysql5.5/mysql-test; perl mysql-test-run.plPlease report any problems with the / opt/mysql5.5/scripts/mysqlbug script!

IX. Setting environment variables

[root@node4 ~] # vi / root/.bash_profile-add parameters to PATH=$PATH:$HOME/bin: PATH=$PATH:$HOME/bin:/opt/mysql5.5/bin:/opt/mysql5.5/lib [root@node4 ~] # source / root/.bash_profile

Start mysql manually

[root@node4 mysql5.5] #. / bin/mysqld_safe-- user=mysql & / / start MySql but cannot stop [1] 27412 [root@node4 mysql5.5] # 130728 08:34:38 mysqld_safe Logging to'/ opt/mysql5.5/data/node4.err'. 130728 08:34:38 mysqld_safe Starting mysqld daemon with databases from / opt/mysql5.5/data---- here the root user of MYSQL has not yet configured a password, so the value is null. When you need to enter the password, just click the enter key. [root@node4 mysql5.5] # / bin/mysqladmin-u root-p shutdown Enter password: 130728 08:34:46 mysqld_safe mysqld from pid file / opt/mysql5.5/data/node4.pid ended [1] + Done. / bin/mysqld_safe-- user=mysql

Another simple way to start mysql (mysql has been added to the system service)

[root@node4 mysql5.5] # service mysql start [root@node4 mysql5.5] # service mysql stop [root@node4 mysql5.5] # service mysql restart

If the above command appears: a service not recognized by mysql

[root@node4 mysql5.5] # service mysql startmysql.server: unrecognized service

Maybe mysql has not been added to the system service yet, so you can add it in another way:

[root@node4 mysql5.5] # cp support-files/mysql.server / etc/init.d/mysql [root@node4 mysql5.5] # service mysql startStarting MySQL... [OK] [root@node4 mysql5.5] # service mysql stopShutting down MySQL. [OK]

Note: the main thing is to copy the mysql.server to / etc/init.d and name it mysql. Then use # service mysql start to start mysql.

Change the root user password of Mysql and open a remote connection

[root@node4] # / opt/mysql5.5/bin/mysql-u root mysqlWelcome to the MySQL monitor. Commands end with; or\ g.Your MySQL connection id is 1 Server version: 5.5.22-log Source distributionCopyright (c) 2000, 2011, Oracle and/or its affiliates. All rights reserved.Oracle is a registered trademark of Oracle Corporation and/or itsaffiliates. Other names may be trademarks of their respectiveowners.Type 'help;' or'\ h' for help. Type'\ c'to clear the current input statement.mysql > use mysql; Database changedmysql > desc user;---- the ability to add remote connections to root. Mysql > grant all privileges on *. * to root@ "%" identified by "root"; Query OK, 0 rows affected (0.03 sec) mysql > update user set Password = password ('123456') where User='root';Query OK, 5 rows affected (0.02 sec) Rows matched: 5 Changed: 5 Warnings: 0 mysql > select Host,User,Password from user where User='root' +-- + | Host | User | Password | +- -+ | localhost | root | * 6BB4837EB74329105EE4568DDA7DC67ED2CA2AD9 | | node4 | root | * 6BB4837EB74329105EE4568DDA7DC67ED2CA2AD9 | | 127.0.0.1 | root | * 6BB4837EB74329105EE4568DDA7DC67ED2CA2AD9 | |:: 1 | root | * 6BB4837EB74329105EE4568DDA7DC67ED2CA2AD9 | |% | root | * 6BB4837EB74329105EE4568DDA7DC67ED2CA2AD9 | +-- -+ 5 rows in set (0.00 sec) mysql > flush privileges Query OK, 0 rows affected (0.01 sec) mysql > exit;Bye [root@node4] # / opt/mysql5.5/bin/mysql-u root-pEnter password: Welcome to the MySQL monitor. Commands end with; or\ g.Your MySQL connection id is 3 Server version: 5.5.22-log Source distributionCopyright (c) 2000, 2011, Oracle and/or its affiliates. All rights reserved.Oracle is a registered trademark of Oracle Corporation and/or itsaffiliates. Other names may be trademarks of their respectiveowners.Type 'help;' or'\ h' for help. Type'\ c' to clear the current input statement.mysql > show databases; +-+ | Database | +-+ | information_schema | | mysql | | performance_schema | | test | +-+ 4 rows in set (0.10 sec) mysql > select version () +-+ | version () | +-+ | 5.5.22-log | +-+ 1 row in set (0.02 sec)

Appendix:

1. Groupadd mysql

2. Useradd-g mysql mysql

3. Tar zxvf mysql-VERSION.tar.gz

4. Cd mysql-VERSION

5. / configure-- prefix=/usr/local/mysql

-- without-debug

-- enable-thread-safe-client

-- enable-assembler

-- enable-profiling

-- with-mysqld-ldflags=-all-static

-- with-client-ldflags=-all-static

-- with-charset=latin1

-- with-extra-charsets=utf8,gbk

-- with-mysqld-user=mysql

-- without-embedded-server

-- with-server-suffix=bbk

-- with-plugins=innobase,partition

6. Make

7. Make install

8.mkdir data

9.chown mysql:mysql. / data/-R

10. Cp support-files/my-medium.cnf / etc/my.cnf

11. Add: under the my.cnf mysqld tag:

Basedir=/opt/mysql5

Datadir=/opt/mysql5/data

12. / bin/mysql_install_db-default-file=./my.cnf-user=mysql

13. Select version ()

At this point, the study on "how to install MYSQL with source code" is over. I hope to be able to solve your doubts. The collocation of theory and practice can better help you learn, go and try it! If you want to continue to learn more related knowledge, please continue to follow the website, the editor will continue to work hard to bring you more practical articles!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Database

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report