linux下安装mysql 5.5和5.6.32

linux下安装mysql5.5
cmake-2.8.4.tar.gz下载地址:http://download.csdn.net/download/lyd518/4260394
 
cmake-2.8.4.tar.gz、mysql-5.5.10.tar.gz文件存放目录:/usr/local/
 
(1)安装编译源码所需的工具和库(cmake,ncurses-devel,bison)
注意事项:ncurses-devel安装完成,无法自动读取到,需要使用-D参数定义宏,指定头文件和库的所在目录
操作方法如下:
安装方法一(外网)
[root@localhost~]#yum -y install wget ncurses-devel cmake bison
[root@localhost~]#find /usr -name libncurses*          //找到libncurses的安装目录

/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参数定义宏,指定头文件和库的所在目录

安装方法二(内网):获取相应安装文件再安装
安装cmake
[root@localhost local]#tar -zxvf cmake-2.8.4.tar.gz
[root@localhost local]#cd cmake-2.8.4
[root@localhost cmake-2.8.4]#./configure    //根据系统情况自动生成编译时所需的Makefile文件
[root@localhost cmake-2.8.4]#make           //编译源码
[root@localhost cmake-2.8.4]#make install   //安装编译好的程序

安装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

[root@localhost Packages]#find /usr -name libncurses*          //找到libncurses的安装目录

/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 mysql-5.5.10]# cd /media/Packages/
[root@localhost Packages]# ls bison*
bison-2.4.1-5.el6.x86_64.rpm
[root@localhost Packages]# rpm -ivh bison-2.4.1-5.el6.x86_64.rpm 
(2)创建mysql的安装目录及数据库存放目录

[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
 
linux下安装mysql5.7.32
参考链接:https://blog.csdn.net/qq_39151461/article/details/113481522
 
mysql安装问题解决
mysql最大连接数修改:my.conf
mysql安装报错日志:
/usr/local/mysql/data 下的 localhost.localdomain.err
没有my.cnf文件的解决方法:
拷贝/usr/local/mysql/support-files下的my-medium.cnf 到/etc/my.cnf
cp /usr/local/mysql/support-files/my-medium.cnf /etc/my.cnf
env: /etc/init.d/mysqld: 权限不够,解决方法如下
chmod a+wrx /etc/init.d/mysql
mysql启动失败,授权问题,解决如下
chmod 777 mysql
授权所有客户端都可以访问
use mysql;
GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY '123456' WITH GRANT OPTION; 
flush privileges;
 

mysql启动失败参考链路:https://www.jb51.net/database/307185q69.htm

posted on 2021-12-03 15:00  seamy  阅读(175)  评论(0编辑  收藏  举报