mysql的安装cmake方式

一般分为以下几种

yum
rpm包
常规编译安装
cmake安装
二进制包免安装

如何选择

个人使用yum或rpm包安装

企业使用多用常规编译和cmake及二进制包免安装

数量少的话
5.1.x版本选择使用常规编译安装
5.5.x版本选择使用cmake方式编译安装

数量多的话
直接使用二进制包免安装

首先查看系统环境

[root@localhost ~]# cat /etc/redhat-release 
CentOS release 6.5 (Final)
[root@localhost ~]# uname -r
2.6.32-431.el6.x86_64
[root@localhost ~]# uname -m
x86_64

在安装cmake软件,需要安装gcc和gcc-c++

yum -y install gcc

yum -y install gcc-c++

编译安装完cmake后,需要安装依赖包

yum install ncurses-devel -y

记住先要安装用户和组
[root@localhost ~]# groupadd mysql
[root@localhost ~]# useradd mysql -s /sbin/nologin -M -g mysql

依赖包安装完后,cd进入mysql的目录进行cmake操作

cmake -DCMAKE_INSTALL_PREFIX=/application/mysql-5.5.32 \
-DMYSQL_DATADIR=/application/mysql-5.5.32/data \
-DMYSQL_UNIX_ADDR=/application/mysql-5.5.32/tmp/mysql.sock \
-DDEFAULT_CHARSET=utf8 \
-DDEFAULT_COLLATION=utf8_general_ci \
-DEXTRA_CHARSETS=gbk,gb2312,utf8,ascii \
-DENABLED_LOCAL_INFILE=ON \
-DWITH_INNOBASE_STORAGE_ENGINE=1 \
-DWITH_FEDERATED_STORAGE_ENGINE=1 \
-DWITH_BLACKHOLE_STORAGE_ENGINE=1 \
-DWITHOUT_EXAMPLE_STORAGE_ENGINE=1 \
-DWITH_FAST_MUTEXES=1 \
-DWITH_ZLIB=bundled \
-DENABLED_LOCAL_INFILE=1 \
-DWITH_READLINE=1 \
-DWITH_EMBEDDED_SERVER=1 \
-DWITH_DEBUG=0 \


-DWITHOUT_PARTITION_STORAGE_ENGINE=1 \           貌似因为64位主机编译不过去!!!
-DWITH_MYISAM_STORAGE_ENGINE=1 \
-DWITH_ARCHIVE_STORAGE_ENGINE=1 \
-DENABLED_LOCAL_INFILE=1 \
-DEXTRA_CHARSETS=all ```
执行成功返回下面代码

Build files have been written to: /root/lamp/mysql-5.5.32

make && install
安装完成

[100%] Built target my_safe_process #此处make完成
….
….
….
— Installing: /application/mysql-5.5.32/support-files/solaris/postinstall-solaris #此处make install 完成


建立link

ln -s /application/mysql-5.5.32/ application/mysql


建立my.cnf

[root@localhost /]# cp /application/mysql-5.5.32/support-files/my-small.cnf /etc/my.cnf
cp:是否覆盖”/etc/my.cnf”? y

配置环境变量

echo ‘export PATH=/application/mysql/bin:$PATH’ >> /etc/profile
tail -l /etc/profile
source /etc/profile
echo $PATH

给mysql用户和mysql用户组授权

chown -R mysql.mysql /application/mysql/data/

chmod -R 1777 /tmp/

初始化db脚本,假如有两个ok,就证明成功

[root@localhost /]# cd /application/mysql/scripts/
[root@localhost scripts]# ./mysql_install_db –basedir=/application/mysql/ –datadir=/application/mysql/data/ –user=mysql
Installing MySQL system tables…
OK
Filling help tables…
OK


修改hosts文件

vim /etc/hosts

加入www


加入mysqld脚本

cp /root/lamp/mysql-5.5.32/support-files/mysql.server /etc/init.d/mysqld

加入mysqld脚本执行权限

chmod +x /etc/init.d/mysqld


执行mysqld运行

[root@localhost scripts]# /etc/init.d/mysqld start
Starting MySQL… [确定]
[root@localhost scripts]# netstat -lntup | grep 3306
tcp 0 0 0.0.0.0:3306 0.0.0.0:* LISTEN 2671/mysqld


进入mysql服务器,如果之前配置了环境变量了,就可以执行mysql命令

mysql


删除空用户
mysql> select user,host from mysql.user;
userhost
+——+———————–+
root127.0.0.1
root::1
localhost
rootlocalhost
localhost.localdomain
rootlocalhost.localdomain

6 rows in set (0.00 sec)

mysql> delete from mysql.user where user =”;
Query OK, 2 rows affected (0.09 sec)

mysql> select user,host from mysql.user;
userhost
+——+———————–+
root127.0.0.1
root::1
rootlocalhost
rootlocalhost.localdomain

4 rows in set (0.00 sec)

mysql>


授权system管理员

mysql> grant all privileges on . to system@’localhost’ identified by ‘longjq’ with grant option;
Query OK, 0 rows affected (0.00 sec)


修改mysql密码

/application/mysql//bin/mysqladmin -u root password ‘123456’
/application/mysql//bin/mysqladmin -u root -h localhost.localdomain password ‘new-password’


加入启动管理

[root@localhost scripts]# chkconfig –list mysqld
mysqld 0:关闭 1:关闭 2:启用 3:启用 4:启用 5:启用 6:关闭`

故障排除

登录不了mysql?删除文件,重新初始化

# mysql
access denied for user 'localhost'......
# pkill mysqld
# lsof -i :3306
# rm -fr /application/mysql/data/*
# /application/mysql/scripts/mysql_install_db --basedir=/application/mysql/ --datadir=/application/mysql/data/ --user=mysql

字符集错误?

[root@localhost scripts]# cat /etc/sysconfig/i18n 
#LANG="zh_CN.GB18030"#这里改成zh_CN.UTF-8
LANG="zh_CN.UTF-8"  
    原文作者:甄城
    原文地址: https://segmentfault.com/a/1190000003880140
    本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系博主进行删除。
点赞