欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  科技

cmake编译安装mysql

程序员文章站 2023-04-07 11:33:22
运维开发技术交流群欢迎大家加入一起学习(QQ:722381733) 前言:这里我使用的安装方式是(cmake编译),我选择的版本是:cmake-2.8.8.tar.gz、mysql-5.5.32.tar.gz 一、安装cmake 1、解压cmake压缩包 2、解析 3、安装 注:安装完成后,记得使用 ......

运维开发技术交流群欢迎大家加入一起学习(qq:722381733)

前言:这里我使用的安装方式是(cmake编译),我选择的版本是:cmake-2.8.8.tar.gz、mysql-5.5.32.tar.gz

[root@mysql package]# ll
total 29580
-rw-r--r-- 1 root root  5691656 may 29 11:52 cmake-2.8.8.tar.gz
-rw-r--r-- 1 root root 24596474 may 29 11:53 mysql-5.5.32.tar.gz
[root@mysql package]# 

 

一、安装cmake

 

  1、解压cmake压缩包

[root@mysql package]# tar xf cmake-2.8.8.tar.gz 
[root@mysql package]# ls
cmake-2.8.8  cmake-2.8.8.tar.gz  mysql-5.5.32.tar.gz
[root@mysql package]# 

  2、解析

[root@mysql package]# cd cmake-2.8.8
[root@mysql cmake-2.8.8]# ./configure
---------------------------------------------
cmake 2.8.8, copyright 2000-2011 kitware, inc.
found gnu toolchain
c compiler on this system is: gcc 
c++ compiler on this system is: g++ 
makefile processor on this system is: gmake
g++ is gnu compiler
g++ has stl in std:: namespace
g++ has ansi streams
g++ has streams in std:: namespace

  3、安装

[root@mysql cmake-2.8.8]# echo $?
0
[root@mysql cmake-2.8.8]# gmake && gmake install
scanning dependencies of target cmiml_test
[  1%] building c object utilities/kwiml/test/cmakefiles/cmiml_test.dir/test.c.o
[  1%] building c object utilities/kwiml/test/cmakefiles/cmiml_test.dir/test_abi_c.c.o
[  1%] building c object utilities/kwiml/test/cmakefiles/cmiml_test.dir/test_int_c.c.o
[  1%] building c object utilities/kwiml/test/cmakefiles/cmiml_test.dir/test_include_c.c.o
[  2%] building cxx object utilities/kwiml/test/cmakefiles/cmiml_test.dir/test_abi_cxx.cxx.o
[  2%] building cxx object utilities/kwiml/test/cmakefiles/cmiml_test.dir/test_int_cxx.cxx.o
[  2%] building cxx object utilities/kwiml/test/cmakefiles/cmiml_test.dir/test_include_cxx.cxx.o

  注:安装完成后,记得使用“echo $?”,检查下!输出0表示成功,输出1表示失败。

 

二、开始安装mysql 

  1、首先需要安装(ncurses-devel)依赖包

[root@mysql cmake-2.8.8]# cd ..
[root@mysql package]# yum install ncurses-devel -y
loaded plugins: fastestmirror
loading mirror speeds from cached hostfile
 * base: mirrors.zju.edu.cn
 * extras: centos.ustc.edu.cn
 * updates: mirrors.zju.edu.cn
resolving dependencies
--> running transaction check
---> package ncurses-devel.x86_64 0:5.9-14.20130511.el7_4 will be installed
#############安装完成后检查###########
[root@mysql package]# rpm -aq|grep ncurses-devel
ncurses-devel-5.9-14.20130511.el7_4.x86_64
[root@mysql package]#

 

  2、解压mysql压缩包

[root@mysql package]# tar xf mysql-5.5.32.tar.gz 
[root@mysql package]# ls
cmake-2.8.8  cmake-2.8.8.tar.gz  mysql-5.5.32  mysql-5.5.32.tar.gz
[root@mysql package]# 

  3、创建虚拟用户

[root@mysql package]# useradd mysql -s /sbin/nologin -m
[root@mysql package]# id mysql
uid=1000(mysql) gid=1000(mysql) groups=1000(mysql)
[root@mysql package]# 

  4、配置解析

[root@mysql package]# cd mysql-5.5.32
[root@mysql mysql-5.5.32]# 
[root@mysql mysql-5.5.32]# cmake . -dcmake_install_prefix=/usr/local/mysql-5.5.32 -dmysql_datadir=/usr/local/mysql-5.5.32/data -dmysql_unix_addr=/usr/local/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 -dwithout_partition_storage_engine=1 -dwith_fast_mutexes=1 -dwith_zlib=bundled -denabled_local_infile=1 -dwith_readline=1 -dwith_embedded_server=1 -dwith_debug=0

  5、安装

[root@mysql mysql-5.5.32]# make && make install
scanning dependencies of target info_bin
[  0%] built target info_bin
scanning dependencies of target info_src
[  0%] built target info_src
scanning dependencies of target abi_check
[  0%] built target abi_check
scanning dependencies of target zlib

  6、创建软连接

[root@mysql mysql-5.5.32]# ln -s /usr/local/mysql-5.5.32/ /usr/local/mysql
[root@mysql mysql-5.5.32]# readlink /usr/local/mysql
/usr/local/mysql-5.5.32/
[root@mysql mysql-5.5.32]# 

  7、配置环境

[root@mysql mysql-5.5.32]# cd ..
[root@mysql package]# echo 'export path=/usr/local/mysql/bin:$path' >>/etc/profile
[root@mysql package]# tail -1 /etc/profile
export path=/usr/local/mysql/bin:$path
[root@mysql package]# source /etc/profile
[root@mysql package]# echo $path
/usr/local/mysql/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin
[root@mysql package]# 

  8、拷贝、查看、设置属主、及添加tmp权限

[root@mysql package]# \cp mysql-5.5.32/support-files/my-small.cnf /etc/my.cnf
[root@mysql package]# ll /usr/local/mysql/data/
total 0
drwxr-xr-x 2 root root 20 may 31 11:51 test
[root@mysql package]# chown -r mysql.mysql /usr/local/mysql/data/
[root@mysql package]# chmod -r 1777 /tmp/
[root@mysql package]# 

  9、初始化数据库

[root@mysql package]# cd /usr/local/mysql/scripts/
[root@mysql scripts]# ./mysql_install_db --basedir=/usr/local/mysql/ --datadir=/usr/local/mysql/data/ --user=mysql 
installing mysql system tables...
ok
filling help tables...
ok

  注:看到两个ok表示成功

   10、设置开机启动

[root@mysql scripts]# cd /package/mysql-5.5.32
[root@mysql mysql-5.5.32]# /bin/cp support-files/mysql.server /etc/init.d/mysqld
[root@mysql mysql-5.5.32]# chmod +x /etc/init.d/mysqld
[root@mysql mysql-5.5.32]# chkconfig --add mysqld
[root@mysql mysql-5.5.32]# chkconfig mysqld on
[root@mysql mysql-5.5.32]# chkconfig --list mysqld

note: this output shows sysv services only and does not include native
      systemd services. sysv configuration data might be overridden by native
      systemd configuration.

      if you want to list systemd services use 'systemctl list-unit-files'.
      to see services enabled on particular target use
      'systemctl list-dependencies [target]'.

mysqld             0:off    1:off    2:on    3:on    4:on    5:on    6:off
[root@mysql mysql-5.5.32]# 

  11、启动mysql数据库

[root@mysql mysql-5.5.32]# /etc/init.d/mysqld start
starting mysql.. success! 
[root@mysql mysql-5.5.32]# 

  12、查看端口进程

[root@mysql mysql-5.5.32]# lsof -i:3306
command   pid  user   fd   type device size/off node name
mysqld  51146 mysql   10u  ipv4  82600      0t0  tcp *:mysql (listen)
[root@mysql mysql-5.5.32]# netstat -lnutp|grep 3306
tcp        0      0 0.0.0.0:3306            0.0.0.0:*               listen      51146/mysqld        
[root@mysql mysql-5.5.32]# ps -ef|grep 3306
mysql    51146 50900  0 14:13 pts/1    00:00:00 /usr/local/mysql-5.5.32/bin/mysqld --basedir=/usr/local/mysql-5.5.32 --datadir=/usr/local/mysql-5.5.32/data --plugin-dir=/usr/local/mysql-5.5.32/lib/plugin --user=mysql --log-error=/usr/local/mysql-5.5.32/data/mysql.err --pid-file=/usr/local/mysql-5.5.32/data/mysql.pid --socket=/usr/local/mysql-5.5.32/tmp/mysql.sock --port=3306
root     51170 16240  0 14:14 pts/1    00:00:00 grep --color=auto 3306
[root@mysql mysql-5.5.32]# 

注:如果要重新初始化只要删除data目录库文件存储地或者新建一个库文件存储地,重新初始化,提示两个ok就是成功

##这里就基本上安装好了,有没有觉得比make&&make install高大上一点哈,下面是一些mysql的优化。

 

  三、mysql数据的一些小优化

这里就不一一说明了,主要是自己懒而且菜,希望能满足大伙的工作要求

进入数据库
mysql 查看所有用户 select user,host from mysql.user; (方式一)删除系统默认的 delete from mysql.user where user=''; delete from mysql.user where host='主机名'; delete from mysql.user where host='::1'; select user,host from mysql.user; ##### 只保留这两个 ####### mysql> select user,host from mysql.user; +------+-----------+ | user | host | +------+-----------+ | root | 127.0.0.1 | | root | localhost | +------+-----------+ 2 rows in set (0.00 sec) mysql> ######################### 删除test库 drop database test; show databases; (方式二)干脆把全部删除了,添加额外的管理员 删除全部用户 delete from mysql.user; 添加额外的授权管理员用户 grant all privileges on *.* to system@'localhost' identified by '123456' with grant option; 字符集路径 vi /etc/locale.conf #centos7 vi /etc/sysconfig/il8n #centos6 mysql创建密码 /application/mysql//bin/mysqladmin -u root password '123456' mysql修改密码 /application/mysql//bin/mysqladmin -u root -poldboy123 password '112233'