linux下安装mysql 5.5和5.6.32
/usr/lib64/libncursesw.so
/usr/lib64/libncurses.so
[root@localhost~]#cd /usr/local/mysql-5.5.10
[root@localhost mysql-5.5.10]#cmake . -DCURSES_LIBRARY=/usr/lib64/libncurses.so -DCURSES_INCLUDE_PATH=/usr/include //用-D参数定义宏,指定头文件和库的所在目录
[root@localhost local]#cd cmake-2.8.4
安装ncurses-devel
上传文件CentOS-6.5-x86_64-bin-DVD1.iso到目录usr下
[root@localhost~]#mkdir /media/
[root@localhost~]#mount -o loop /usr/CentOS-6.5-x86_64-bin-DVD1.iso /media
[root@localhost~]#cd /media/Packages/
[root@localhost Packages]#ls ncurses-devel*
[root@localhost Packages]#rpm -ivh ncurses-devel-5.7-3.20090208.el6.x86_64.rpm
/usr/lib64/libncursesw.so
/usr/lib64/libncurses.so
[root@localhost Packages]#cd /usr/local/mysql-5.5.10
[root@localhost mysql-5.5.10]#cmake . -DCURSES_LIBRARY=/usr/lib64/libncurses.so - DCURSES_INCLUDE_PATH=/usr/include //用-D参数定义宏,指定头文件和库的所在目录
安装bison
[root@localhost~]#mkdir -p /usr/local/mysql //安装mysql
[root@localhost~]#mkdir -p /usr/local/mysql/data //存放数据库
(3)创建mysql用户组及用户
[root@localhost~]#groupadd mysql //创建mysql用户组
[root@localhost~]#useradd -r -g mysql mysql //创建mysql用户
(4)安装mysql
[root@localhost~]#cd /usr/local
[root@localhost local]#tar -zxvf mysql-5.5.10.tar.gz
[root@localhost local]#cd mysql-5.5.10
[root@localhost mysql-5.5.10]#cmake \
-DCMAKE_INSTALL_PREFIX=/usr/local/mysql \
-DMYSQL_UNIX_ADDR=/usr/local/mysql/mysql.sock \
-DMYSQL_DATADIR=/usr/local/mysql/data \
-DDEFAULT_CHARSET=utf8 \
-DDEFAULT_COLLATION=utf8_general_ci \
-DEXTRA_CHARSETS=all \
-DENABLED_LOCAL_INFILE=1
参数说明:
-DCMAKE_INSTALL_PREFIX=/usr/local/mysql //安装目录
-DINSTALL_DATADIR=/usr/local/mysql/data //数据库存放目录
-DDEFAULT_CHARSET=utf8 //使用utf8字符
-DDEFAULT_COLLATION=utf8_general_ci //校验字符
-DEXTRA_CHARSETS=all //安装所有扩展字符集
-DENABLED_LOCAL_INFILE=1 //允许从本地导入数据
[root@localhost mysql-5.5.10]#make //编译源码
[root@localhost mysql-5.5.10]#make install //安装编译好的程序
注意事项:
重新编译时,需要清除旧的对象文件和缓存信息。
# make clean
# rm -f CMakeCache.txt
# rm -rf /etc/my.cnf
执行cmake \等语句若出现以下两个报错信息是由于没有安装编译源码所需的工具和库(ncurses-devel,bison):
报错信息1:
-- Could NOT find Curses (missing: CURSES_LIBRARY CURSES_INCLUDE_PATH)
CMake Error at cmake/readline.cmake:82 (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:126 (FIND_CURSES)
cmake/readline.cmake:216 (MYSQL_USE_BUNDLED_LIBEDIT)
CMakeLists.txt:250 (MYSQL_CHECK_READLINE)
-- Configuring incomplete, errors occurred!
报错信息1的解决方法:安装ncurses-devel
报错信息2:
-- MySQL 5.5.10
Warning: Bison executable not found in PATH
-- Configuring done
-- Generating done
-- Build files have been written to: /usr/local/mysql-5.5.10
报错信息2的解决方法:安装bison
(5)修改目录拥有者
[root@localhost mysql-5.5.10]# cd /usr/local/mysql
[root@localhost mysql]# chown -R root:mysql . //把当前目录中所有文件的所有者所有者设为root,所属组为mysql 注意事项:该命令后面有一个“.”,需拷贝完全
[root@localhost mysql]#chown -R mysql:mysql /usr/local/mysql/data
[root@localhost mysql]#cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysql //将mysql的启动服务添加到系统服务中
(6)创建系统数据库的表
[root@localhost mysql]# cd /usr/local/mysql
[root@localhost mysql]# scripts/mysql_install_db --user=mysql --datadir=/usr/local/mysql/data
(7)设置环境变量
[root@localhost~]# vi /root/.bash_profile
在PATH=$PATH:$HOME/bin添加参数为:
PATH=$PATH:$HOME/bin:/usr/local/mysql/bin:/usr/local/mysql/lib
[root@localhost~]#source /root/.bash_profile //生效环境变量
(8)启动MySQL服务
[root@localhost~]#service mysql start //启动mysql
[root@localhost~]#service mysql stop //停止mysql
[root@localhost~]#service mysql restart //重启mysql
(9)设置开机自启动mysql服务
[root@localhost~]#chkconfig mysql on
(10)重启电脑
[root@localhost~]#reboot
(11)修改MySQL用户root的密码和远程访问权限
[root@localhost~]#cd /usr/local/mysql
[root@localhost mysql]#mysql -u root
mysql>use mysql;
mysql>GRANT ALL PRIVILEGES ON *.* TO root@"%" IDENTIFIED BY "123456";
mysql>update user set Password = password('123456') where User='root';
mysql>flush privileges;
mysql>exit;
[root@localhost mysql]#mysql -u root -p123456 //检测下MySQL用户root密码是否生效
[root@localhost mysql]#drop database test; //删除test数据库
(12)关闭防火墙
[root@localhost~]#service iptables stop
(13)使用Navicat连接mysql
出现以下报错信息Can't get hostname for your address的解决方法
vim /etc/my.cnf
[mysqld]中增加以下内容:
skip-name-resolve # 忽略主机名的方式访问
lower_case_table_names=1 # 忽略数据库表名大小写
修改保存后,重启mysql
mysql启动失败参考链路:https://www.jb51.net/database/307185q69.htm