博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
mysql编译安装
阅读量:5328 次
发布时间:2019-06-14

本文共 3862 字,大约阅读时间需要 12 分钟。

Linux下编译安装MySQL

 

下面是在 CentOS 6.5 下编译安装 MySQL 5.6.20 。

1. 首先卸载系统自带的 mysql
# yum remove mysql 
2.安装cmake 
下载cmake源码
# wget http://www.cmake.org/files/v2.8/cmake-2.8.5.tar.gz
# tar xzfv cmake-2.8.5.tar.gz
# cd cmake-2.8.5
# ./configure
( 如果提示没安装C++编译器就先安装C++编译器:# yum -y install gcc-c++ )
# make 
# make install
查看 cmake 版本
# cmake -version
3.安装 ncurses 和 bison
# yum -y install ncurses-devel
# yum -y install bison
4. 创建mysql组和用户
# groupadd mysql
# useradd -g mysql mysql 
5. 创建数据库目录及分配访问权限
# mkdir -p /u01/app/mysql
# chown -R root:mysql /u01/app/mysql
# chown -R mysql:mysql /u01/app/mysql/data
6. 编译安装mysql
下载mysql源码
# wget http://cdn.mysql.com/Downloads/MySQL-5.6/mysql-5.6.20.tar.gz
# tar xzfv mysql-5.6.20.tar.gz
# cd mysql-5.6.20
# cmake . -DCMAKE_INSTALL_PREFIX=/u01/app/mysql -DMYSQL_DATADIR=/u01/app/mysql/data -DSYSCONFDIR=/etc
参数说明:
-DCMAKE_INSTALL_PREFIX    //安装根目录
-DINSTALL_DATADIR         //数据存储目录
-DSYSCONFDIR              //配置文件(my.cnf)目录
# make 
# make install
7. 配置 mysql
# cd /u01/app/mysql
# cp ./support-files/my-default.cnf /etc/my.cnf 
# vi /etc/my.cnf
在 [mysqld] 段修改
basedir = /u01/app/mysql
datadir = /u01/app/mysql/data
保存退出编辑。
8. 初始化数据库
# cd /u01/app/mysql
# ./scripts/mysql_install_db --basedir=/u01/app/mysql --datadir=/u01/app/mysql/data --defaults-file=/etc/my.cnf --user=mysql
# cp ./support-files/mysql.server /etc/rc.d/init.d/mysqld
# chmod 755 /etc/rc.d/init.d/mysqld
# chkconfig --add mysqld
9. 设置启动脚本变量 
# vi /etc/rc.d/init.d/mysqld
basedir=/u01/app/mysql
datadir=/u01/app/mysql/data
保存退出。
10. 设置变量环境
# echo "PATH=$PATH:/u01/app/mysql/bin" >> /etc/profile (永久生效)
# export PATH=$PATH:/u01/app/mysql/bin (当前生效)
11. 启动服务
# service mysqld start
/etc/init.d/mysqld: line 46: /u01/app/mysql: is a directory
/etc/init.d/mysqld: line 47: /u01/app/mysql/data: is a directory
Starting MySQL.                                            [  OK  ]

如果这一步出现错误:Starting MySQL. ERROR! The server quit without updating PID file

除了网络搜索到的常见kill进程等方法之外,如果不起作用可参考以下页面的方法:

http://blog.sina.com.cn/s/blog_637e04c9010117ri.html

尝试了其中的solution 2 移除配置文件解决了问题

12. 设置数据库管理员root密码
# mysqladmin -u root password '123456'
(注:在当前会话窗口操作,否则会出现 “mysqladmin: command not found” 错误,除非重新启动系统。)
重新启动服务
# service mysqld restart 
/etc/init.d/mysqld: line 46: /u01/app/mysql: is a directory
/etc/init.d/mysqld: line 47: /u01/app/mysql/data: is a directory
/etc/init.d/mysqld: line 46: /u01/app/mysql: is a directory
/etc/init.d/mysqld: line 47: /u01/app/mysql/data: is a directory
Shutting down MySQL.                                       [  OK  ]
/etc/init.d/mysqld: line 46: /u01/app/mysql: is a directory
/etc/init.d/mysqld: line 47: /u01/app/mysql/data: is a directory
Starting MySQL.                                            [  OK  ]
13. 进入 MySQL
# mysql -u root -p
(注:在当前会话窗口操作,否则会出现 “mysql: command not found” 错误,除非重新启动系统。)
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 3
Server version: 5.6.20 Source distribution
Copyright (c) 2000, 2014, 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> 
登录成功了,赶快感受一下 :)
mysql> use mysql;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A
Database changed
mysql> select Host,User,Password from user; 
+-----------------------+------+-------------------------------------------+
| Host                  | User | Password                                  |
+-----------------------+------+-------------------------------------------+
| localhost             | root | *6BB4837EB74329105EE4568DDA7DC67ED2CA2AD9 |
| localhost.localdomain | root |                                           |
| 127.0.0.1             | root |                                           |
| ::1                   | root |                                           |
| localhost             |      |                                           |
| localhost.localdomain |      |                                           |
+-----------------------+------+-------------------------------------------+
6 rows in set (0.00 sec)
mysql> 

转载于:https://www.cnblogs.com/masamia/p/4772006.html

你可能感兴趣的文章
巧用Win+R
查看>>
浅析原生js模仿addclass和removeclass
查看>>
Python中的greenlet包实现并发编程的入门教程
查看>>
java中遍历属性字段及值(常见方法)
查看>>
深入理解jQuery框架-框架结构
查看>>
YUI3自动加载树实现
查看>>
python知识思维导图
查看>>
当心JavaScript奇葩的逗号表达式
查看>>
App Store最新审核指南(2015年3月更新版)
查看>>
织梦MIP文章内容页图片适配百度MIP规范
查看>>
点击复制插件clipboard.js
查看>>
[Kali_BT]通过低版本SerialPort蓝牙渗透功能手机
查看>>
C语言学习总结(三) 复杂类型
查看>>
HNOI2018
查看>>
【理财】关于理财的网站
查看>>
Ubunt中文乱码
查看>>
《当幸福来敲门》读后
查看>>
【转】系统无法进入睡眠模式解决办法
查看>>
省市县,循环组装,整合大数组
查看>>
stm32中字节对齐问题(__align(n),__packed用法)
查看>>