标签:mysql
刚工作不久,按捺不住一颗骚动的心,2333333
总结在安装数据库过程中遇到的错误与解决方法
目的:搭建lamp或lnmp架构,系统使用的是centos6,mysqld版本是5.5的
首先安装需要编译的库文件:
yum install gcc cpp glibc glibc-devel gcc-c++
yum -y install gcc make libtool automake autoconf rrdtool-devel libpcap-devel gdbm-devel zlib-devel geoip-devel
下载mysql5.5的版本:wget http://mirrors.sohu.com/mysql/MySQL-5.5/mysql-5.5.42-linux2.6-x86_64.tar.gz
下载至目录后解压:tar zxf mysql-5.5.42-linux2.6-x86_64.tar.gz -C /usr/local/src/
创建mysqld用户和组
/usr/sbin/groupadd mysql
/usr/sbin/useradd -g mysql mysql
进入cd /usr/local/src/mysql-5.5目录下开始编译
cmake . -DCMAKE_INSTALL_PREFIX=/usr/local/mysql \
-DMYSQL_DATADIR=/usr/local/mysql-5.5.42data \
-DMYSQL_UNIX_ADDR=/usr/local/mysql-5.5.42tmp/mysql.sock \
-DDEFAULT_CHARSET=gbk \
-DDEFAULT_COLLATION=gbk_chinese_ci \
-DENABLED_LOCAL_INFILE=ON \
-DWITH_INNOBASE_STORAGE_ENGINE=1 \
-DWITH_FEDERATED_STORAGE_ENGINE=1 \
-DWITH_BLACKHOLE_STORAGE=1 \
-DWITHOUT_EXAMPLE_STORAGE_ENGINE=1 \
-DWITHOUT_PARTITION_STORAGE_ENGINE=1
make
make install
给予mysqld +w目录权限:chmod +w /usr/local
更改目录所有者与所有主权限:chown +R mysql:mysql /usr/local/mysql
设置文件软连接:ln -s /usr/local/mysql/lib/libmysqlclient.so.16 /usr/lib/libmysqlclient.so.16
创建mysql所需目录:
mkdir -p /var/mysql/
mkdir -p /var/mysql/data/
mkdir -p /var/mysql/log
更改目录所有者权限:chown -R mysql:mysql /var/mysql/
进入目录下拷贝配置模板:cd support-files/
cp my-large.cnf /var/mysql/my.cnf //根据系统配置拷贝不同模板
cp mysql.server /etc/rc.d/init.d/mysqld //拷贝启动脚本
初始化数据库
/usr/local/mysql/scripts/mysql_install_db \
--defaults-file=/var/mysql/my.cnf \
--basedir=/usr/local/mysql \
--datadir=/var/mysql/data \
--user=mysql
设置开机启动服务
chmod +x /etc/init.d/mysqld
vim /etc/init.d/mysqld(编辑此文件,查找并修改以下变量内容:)
basedir=/usr/local/mysql
datadir=/var/mysql/data
加入启动项:
chkconfig --add mysqld
chkconfig --level 345 mysqld on
优化执行路径,程序库路径 :
[root@localhost mysql]# echo "export PATH=$PATH:/usr/local/mysql/bin/" >>/etc/profile
[root@localhost mysql]# source /etc/profile
[root@localhost mysql]# echo "/usr/local/mysql/lib/" >>/etc/ld.so.conf
[root@localhost mysql]# ldconfig --刷新库文件搜索路径,使修改生效
启动服务:service mysqld restart
设置数据库root密码:mysqladmin -uroot password nowpasswd
[root@xiangchen support-files]# mysql -u root -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 3
Server version: 5.5.42-log 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>
安装过程中遇到的错误:拷贝系统配置文件(my.cnf)过程中要针对系统配置拷贝不同的文件,否则mysql启动不成功!
此贴随时增删改
本文出自 “linux窝” 博客,请务必保留此出处http://xiangcc.blog.51cto.com/10201823/1650341
标签:mysql
原文地址:http://xiangcc.blog.51cto.com/10201823/1650341