[iyunv@node4 ~]# groupadd mysql
[iyunv@node4 ~]# useradd -r -g mysql mysql
五、安装mysql
[iyunv@node4 ~]# tar -zxvf mysql-5.5.22.tar.gz
[iyunv@node4 ~]# cd mysql-5.5.22
----编译出现以下错误,需要ncurses-devel
[iyunv@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)
Alternatively you can run:
/opt/mysql5.5/bin/mysql_secure_installation
which will also give you the option of removing the test
databases 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.pl
cd /opt/mysql5.5/mysql-test ; perl mysql-test-run.pl
Please report any problems with the /opt/mysql5.5/scripts/mysqlbug script!
九、设置环境变量
[iyunv@node4 ~]# vi /root/.bash_profile
----在PATH=$PATH:$HOME/bin添加参数为:
[iyunv@node4 mysql5.5]# service mysql start
[iyunv@node4 mysql5.5]# service mysql stop
[iyunv@node4 mysql5.5]# service mysql restart
如果上述命令出现:mysql未识别的服务
[iyunv@node4 mysql5.5]# service mysql start
mysql.server: unrecognized service
则可能mysql还没添加到系统服务中,下面用另一个方法添加:
[iyunv@node4 mysql5.5]# cp support-files/mysql.server /etc/init.d/mysql
[iyunv@node4 mysql5.5]# service mysql start
Starting MySQL... [ OK ]
[iyunv@node4 mysql5.5]# service mysql stop
Shutting down MySQL. [ OK ]
注意:主要是将mysql.server拷贝到/etc/init.d中,命名为mysql。然后再用#service mysql start 来启动mysql即可。
十二、修改Mysql的root用户密码以及打开远程连接
[iyunv@node4 ~]# /opt/mysql5.5/bin/mysql -u root mysql
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 1
Server version: 5.5.22-log Source distribution
Copyright (c) 2000, 2011, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql> use mysql;
Database changed
mysql> desc user;
----为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)
[iyunv@node4 ~]# /opt/mysql5.5/bin/mysql -u root -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 3
Server version: 5.5.22-log Source distribution
Copyright (c) 2000, 2011, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
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)
附录:
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.在my.cnf mysqld标签下中添加:
basedir=/opt/mysql5
datadir=/opt/mysql5/data
12. ./bin/mysql_install_db --default-file=./my.cnf --user=mysql
13. select version();