安装的mysql数据库是:mysql-5.6.4-m7,这个版本的数据库要用cmake工具安装。
CMake是一个跨平台的安装(编译)工具,可以用简单的语句来描述所有平台的安装(编译过程)。他能够输出各种各样的makefile或者project文件,能测试编译器所支持的C++特性,类似UNIX下的automake
1、安装cmake
[root@localhost tmp]# cd cmake-2.8.9/
[root@localhost cmake-2.8.9]# ./bootstrap
[root@localhost cmake-2.8.9]#make
[root@localhost cmake-2.8.9]#make install
如果要更新cmake 只需进入相关目录,执行
cmake.
make
make install
or
1、安装 cmake 编译器。
1)、下载cmake
#cd /usr/local/src
#wget http://www.cmake.org/files/v2.8/cmake-2.8.4.tar.gz
2)、解压cmake
#tar -zvxf cmake-2.8.4.tar.gz
3)、配置编译
#cd cmake-2.8.4
#yum -y install gcc
#yum -y install gcc-c++
#yum -y install ncurses-devel
#./configure
#make
#make install
2、安装mysql
[root@localhost mnt]# cd mysql-5.6.4-m7/
[root@localhost mnt]# cmake .
可能回出现下面问题:
-- Could NOT find Curses (missing: CURSES_LIBRARY CURSES_INCLUDE_PATH)
CMake Error at cmake/readline.cmake:83 (MESSAGE):
Call Stack (most recent call first):
按照上面内容提示的方法进行修改:
若是redhat 安装ncurses-devel这个包即可。
[root@localhost mysql-5.6.4-m7]# yum install ncurses-devel*
[root@localhost mysql-5.6.4-m7]# rm CMakeCache.txt
(注意这里是删除CMakeCache.txt
,有一个跟他很相似的文件,别删错了!)
[root@localhost mysql-5.6.4-m7]#make
[root@localhost mysql-5.6.4-m7]#make install
3、安装默认的数据库
[mysql@localhost mysql]$ cd scripts/
[mysql@localhost scripts]$ ls
[mysql@localhost scripts]$ sudo ./mysql_install_db --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data/ --user=mysql
安装完后有这么一段提示,可以仔细看看:
To start mysqld at boot time you have to copy
support-files/mysql.server to the right place for your system
PLEASE REMEMBER TO SET A PASSWORD FOR THE MySQL root USER !
To do so, start the server, then issue the following commands:
/usr/local/mysql//bin/mysqladmin -u root password 'new-password'
/usr/local/mysql//bin/mysqladmin -u root -h localhost.localdomain password 'new-password'
Alternatively you can run:
/usr/local/mysql//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 /usr/local/mysql/ ; /usr/local/mysql//bin/mysqld_safe &
You can test the MySQL daemon with mysql-test-run.pl
cd /usr/local/mysql//mysql-test ; perl mysql-test-run.pl
4、复制mysql配置文件和服务文件到系统配置路径下面
[root@localhost ~]# cd /usr/local/mysql/support-files/
[root@localhost support-files]# cp my-medium.cnf /etc/my.cnf
[root@localhost support-files]# cp mysql.server /etc/init.d/mysqld
5、启动服务
[root@localhost init.d]# service mysqld start
6、增加mysql的root用户密码
[root@localhost init.d]# /usr/local/mysql//bin/mysqladmin -u root password 'mysql'
[root@localhost init.d]# /usr/local/mysql//bin/mysqladmin -u root -h localhost.localdomain password 'mysql'
7、查看启动,看默认的安装路径
[root@localhost ~]# ps -ef | grep mysql
root
5038
1
0 21:54 pts/1
00:00:00 /bin/sh /usr/local/mysql/bin/mysqld_safe --datadir=/usr/local/mysql/data --pid-file=/usr/local/mysql/data/localhost.localdomain.pid
(说明是root用户启动的进程)
mysql
5293
5038
1 21:54 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/localhost.localdomain.err --pid-file=/usr/local/mysql/data/localhost.localdomain.pid --socket=/tmp/mysql.sock --port=3306 (包含路径、端口等)
root
5324
4756
0 21:54 pts/1
00:00:00 grep mysql
8、设置软连接,添加mysql(基本命令), mysqldump(备份命令), mysqladmin(管理命令)到/usr/bins使其能在shell中直接运行
[root@localhost ~]#/usr/local/mysql/bin/mysql /usr/bin
[root@localhost ~]#
/usr/local/mysql/bin/mysqldump /usr/bin
[root@localhost ~]#
/usr/local/mysql/bin/mysqladmin /usr/bin
还可以添加更多的命令
9、连接到数据库
[root@localhost ~]# mysql -u root -p
mysql> GRANT ALL PRIVILEGES on *.* to 'root'@'%' identified by 'cattsoft';
出现error: 'Access denied for user 'root'@'localhost' (using password: NO)'解决方法:
[root@localhost ~]# service mysqld stop
[root@localhost ~]# cd /usr/local/mysql/bin/mysqld_safe --user=mysql --skip-grant-tables --skip-networking &
[root@localhost ~]#mysql -u root
mysql> use mysql
mysql> update user set password=PASSWORD(mysql) where user='root' and host='root' or host='localhost';
mysql> flush privileges;
mysql> quit;
[root@localhost ~]# service mysqld start
[root@localhost ~]# mysql -u root -p
Enter password:
mysql>
对root用新帐号登陆重新授权:
mysql> GRANT ALL PRIVILEGES on *.* to 'root'@'%' identified by mysql;