LNMP服务器搭建-MySQL
参考教程:【千峰教育】
系统版本:
CentOS 6.8
关闭防火墙和Selinux
service iptables stop setenforce 0
安装mysql
(1)创建目录、设置权限
mkdir -p /data/www #创建数据库文件保存目录
chown -R www:www /data/www #设置目录所有者
chmod -R 700 /data/www #设置目录权限
(2)创建mysql管理用户
useradd mysql -s /sbin/nologin #创建用户mysql,不允许直接登录系统
mkdir -p /var/mysql/data #创建mysql数据库存放目录
chown -R mysql:mysql /var/mysql/data #设置mysql数据库目录权限
(3)解压源码包
cd /lnmp/src
tar -zxvf mysql-5.5.62.tar.gz
cd mysql-5.5.62
(4)配置
cmake . -DCMAKE_INSTALL_PREFIX=/usr/local/mysql \ -DMYSQL_UNIX_ADDR=/usr/local/mysql/mysql.sock \ -DDEFAULT_CHARSET=utf8 \ -DDEFAULT_COLLATION=utf8_general_ci \ -DWITH_MYISAM_STORAGE_ENGINE=1 \ -DWITH_INNOBASE_STORAGE_ENGINE=1 \ -DWITH_MEMORY_STORAGE_ENGINE=1 \ -DWITH_READLINE=1 \ -DENABLED_LOCAL_INFILE=1 \ -DMYSQL_DATADIR=/usr/mysql/data \ -DMYSQL_USER=mysql \ -DMYSQL_TCP_PORT=3306
(5)安装
make && make install
(6)配置
cd /usr/local/mysql
cp ./support-files/my-huge.cnf /etc/my.cnf #拷贝配置文件
vim /etc/my.cnf #编辑配置文件,在【mysqld】部分增加
datadir=/var/mysql/data #添加mysql数据库路径
./scripts/mysql_install_db --user=mysql #生成mysql系统数据库
cp ./support-files/mysql.server /etc/rc.d/init.d/mysqld #mysql加入系统启动
vim /etc/rc.d/init.d/mysqld #编辑
basedir=/usr/local/mysql #mysql程序安装路径
datadir=/var/mysql/data #mysql数据库存放目录
chmod 755 /etc/init.d/mysqld #增加执行权限
chkconfig mysqld on #加入开机启动项sock
chown -R mysql /usr/local/mysql #修改msyql所属用户为mysql
service mysqld start #启动mysql
vim /etc/profile #把mysql服务加入系统环境变量
export PATH=$PATH:/usr/local/mysql/bin
source /etc/profile #使配置立即生效
mkdir /var/lib/mysql #创建目录
ln -s /tmp/mysql.sock /var/lib/mysql/mysql.sock #添加软连接
mysql_secure_installation #设置mysql密码,根据提示按Y,回车输入2次密码
或者这样设置密码:
mysqladmin -u root -p password "123456" #直接修改密码
(7)查看mysql状态:
service mysqld status
启动mysql:
service mysqld start|stop|restart
常见错误:
问题一:
安装mysql时,错误提示:
CMake Error at CMakeLists.txt:111 (PROJECT):
No CMAKE_C_COMPILER could be found.
Tell CMake where to find the compiler by setting either the environment
variable "CC" or the CMake cache entry CMAKE_C_COMPILER to the full path to
the compiler, or to the compiler name if it is in the PATH.
CMake Error at CMakeLists.txt:111 (PROJECT):
No CMAKE_CXX_COMPILER could be found.
Tell CMake where to find the compiler by setting either the environment
variable "CXX" or the CMake cache entry CMAKE_CXX_COMPILER to the full path
to the compiler, or to the compiler name if it is in the PATH.
-- Configuring incomplete, errors occurred!
报错意思:
找不到cmake_c_编译器。
解决方法:
安装gcc 和 gcc-c++。
gcc gcc-c++
问题二:安装mysql时,cmake报错:
-- 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:118 (FIND_CURSES)
cmake/readline.cmake:214 (MYSQL_USE_BUNDLED_READLINE)
CMakeLists.txt:394 (MYSQL_CHECK_READLINE)
-- Configuring incomplete, errors occurred!
需要安装Curses library。
yum install -y ncurses*