在CentOs7下利用cmake2.8.4安装mysql5.5.16版本及以上数据库详细步骤(附windows桌面工具教程)
Posted on 2019-10-31 01:33 SliverLee 阅读(361) 评论(0) 编辑 收藏 举报1、下载资源包
链接:https://pan.baidu.com/s/1466x9EuWuby_8Zt1Rfxqgw
提取码:8iyy
2、安装准备
安装5.5及以上的版本和之前的版本不一样了,之前的版本是 解压--- ./configure ---- make && make install ;而5.5及以后的版本可以用cmake进行编译安装;
2.1 安装cmake
[root@Mysql-Redis tools]# tar -zvxf cmake-2.8.4.tar.gz
[root@Mysql-Redis tools]# cd cmake-2.8.4
进入解压出来的目录,然后编译,安装
[root@Mysql-Redis cmake-2.8.4]# ./configure
输入 echo $? ,看看输出的值是不是 0,是的话就没有问题
[root@Mysql-Redis cmake-2.8.4]# echo $?
0
[root@Mysql-Redis cmake-2.8.4]# gmake && gmake install
如果不能编译,则需要安装 gcc 和 g++相关组件
[root@Mysql-Redis cmake-2.8.4]# yum -y install gcc
[root@Mysql-Redis cmake-2.8.4]# yum -y install gcc-c++
[root@Mysql-Redis cmake-2.8.4]# yum install bison
安装之后,再次执行,就可以编译了。
但是还需要安装一个依赖包 ncurses-devel
[root@Mysql-Redis cmake-2.8.4]# yum -y install ncurses-devel
2.2创建mysql用户和用户组
创建组和用户:
[root@Mysql-Redis ~]# groupadd mysql
[root@Mysql-Redis ~]# useradd mysql -s /sbin/nologin -M -g mysql
简单介绍一下 useradd命令
3、安装mysql
3.1 解压mysql文件
[root@Mysql-Redis tools]# tar -zvxf mysql-5.5.16.tar.gz
进入mysql目录
[root@Mysql-Redis tools]# cd mysql-5.5.16
cmake . -DCMAKE_INSTALL_PREFIX=/usr/local/mysql \
-DMYSQL_DATADIR=/usr/local/mysql/data \
-DMYSQL_UNIX_ADDR=/usr/local/mysql/tmp/mysql.sock \
-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
cmake 相关参数选项介绍
-DCMAKE_INSTALL_PREFIX=dir_name 设置mysql安装目录
-DMYSQL_UNIX_ADDR=file_name 设置监听套接字路径,这必须是一个绝对路径名。默认为/tmp/mysql.sock
-DDEFAULT_CHARSET=charset_name 设置服务器的字符集。缺省情况下,MySQL使用latin1的(CP1252西欧)字符集。cmake/character_sets.cmake文件包含允许的字符集名称列表。
-DDEFAULT_COLLATION=collation_name 设置服务器的排序规则。
-DWITH_INNOBASE_STORAGE_ENGINE=1
-DWITH_ARCHIVE_STORAGE_ENGINE=1
-DWITH_BLACKHOLE_STORAGE_ENGINE=1
-DWITH_PERFSCHEMA_STORAGE_ENGINE=1
存储引擎选项:MyISAM,MERGE,MEMORY,和CSV引擎是默认编译到服务器中,并不需要明确地安装。
静态编译一个存储引擎到服务器,使用-DWITH_engine_STORAGE_ENGINE= 1
可用的存储引擎值有:ARCHIVE, BLACKHOLE, EXAMPLE, FEDERATED, INNOBASE (InnoDB), PARTITION (partitioning support), 和PERFSCHEMA (Performance Schema)
-DMYSQL_DATADIR=dir_name 设置mysql数据库文件目录
-DMYSQL_TCP_PORT=port_num 设置mysql服务器监听端口,默认为3306
-DENABLE_DOWNLOADS=bool 是否要下载可选的文件。例如,启用此选项(设置为1),cmake将下载谷歌所使用的测试套件运行单元测试。
3.2编译 安装
[root@Mysql-Redis mysql-5.5.16]# make && make install
这里看到其他的文档,安装地址是带版本号的,然后再设置软链接ln -s /usr/local/mysql-5.5.16/ /usr/local/mysql
3.3配置环境变量
[root@Mysql-Redis mysql-5.5.16]# cd ..
[root@Mysql-Redis tools]# echo 'export PATH=/usr/local/mysql/bin:$PATH' >>/etc/profile
这里的引号必须是英文半角,执行的时候注意下;
查看环境变量
[root@Mysql-Redis tools]# tail -1 /etc/profile
export PATH=/usr/local/mysql/bin:$PATH
[root@Mysql-Redis tools]# source /etc/profile
[root@Mysql-Redis tools]# echo $PATH
/usr/local/mysql/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin
3.4配置权限
[root@Mysql-Redis tools]# cp mysql-5.5.16/support-files/my-small.cnf /etc/my.cnf
[root@Mysql-Redis tools]# ll /usr/local/mysql/data/
total 0
drwxr-xr-x. 2 root root 20 Oct 31 04:58 mysql
drwxr-xr-x. 2 root root 20 Oct 31 04:58 test
我这里比其他的文档多了个mysql的目录,原因尚不清楚。
改变用户及所属组
[root@Mysql-Redis tools]# chown -R mysql.mysql /usr/local/mysql/data/
[root@Mysql-Redis tools]# chmod -R 1777 /tmp/
3.5初始化数据库
输出两个OK,即代表初始化成功
[root@localhost scripts]# cd /usr/local/mysql/scripts/
[root@Mysql-Redis scripts]# ./mysql_install_db --basedir=/usr/local/mysql/ --datadir=/usr/local/mysql/data/ --user=mysql
Installing MySQL system tables...
OK
Filling help tables...
OKTo start mysqld at boot time you have to copy
support-files/mysql.server to the right place for your systemPLEASE REMEMBER TO SET A PASSWORD FOR THE MySQL root USER !
To do so, start the server, then issue the following commands:/usr/local/mysql//bin/mysqladmin -u root password 'new-password'
/usr/local/mysql//bin/mysqladmin -u root -h Mysql-Redis password 'new-password'Alternatively you can run:
/usr/local/mysql//bin/mysql_secure_installationwhich will also give you the option of removing the test
databases and anonymous user created by default. This is
strongly recommended for production servers.See the manual for more instructions.
You can start the MySQL daemon with:
cd /usr/local/mysql/ ; /usr/local/mysql//bin/mysqld_safe &You can test the MySQL daemon with mysql-test-run.pl
cd /usr/local/mysql//mysql-test ; perl mysql-test-run.plPlease report any problems with the /usr/local/mysql//scripts/mysqlbug script!
3.6配置为系统服务
[root@Mysql-Redis ~]# cd /root/tools/mysql-5.5.16
[root@Mysql-Redis mysql-5.5.16]# cp support-files/mysql.server /etc/init.d/mysqld
[root@Mysql-Redis mysql-5.5.16]# chmod -R 755 /etc/init.d/mysqld
[root@Mysql-Redis mysql-5.5.16]# chkconfig --add mysqld
[root@Mysql-Redis mysql-5.5.16]# chkconfig mysqld on
[root@Mysql-Redis mysql-5.5.16]# 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
3.7 启动数据库
[root@Mysql-Redis mysql-5.5.16]# /etc/init.d/mysqld start
Starting MySQL.. SUCCESS!
[root@Mysql-Redis mysql-5.5.16]# netstat -na | grep 3306
tcp 0 0 0.0.0.0:3306 0.0.0.0:* LISTEN
[root@Mysql-Redis mysql-5.5.16]# ps -aux | grep mysqld
root 53647 0.0 0.0 113184 1600 pts/1 S 05:24 0:00 /bin/sh /usr/local/mysql/bin/mysqld_safe --datadir=/usr/local/mysql/data --pid-file=/usr/local/mysql/data/Mysql-Redis.pid
mysql 53878 0.2 1.1 700040 43024 pts/1 Sl 05:24 0:00 /usr/local/mysql/bin/mysqld --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data --plugin-dir=/usr/local/mysql/lib/plugin --user=mysql --log-error=/usr/local/mysql/data/Mysql-Redis.err --pid-file=/usr/local/mysql/data/Mysql-Redis.pid --socket=/usr/local/mysql/tmp/mysql.sock --port=3306
root 54014 0.0 0.0 112712 968 pts/1 S+ 05:26 0:00 grep --color=auto mysqld
4、数据库配置
[root@Mysql-Redis ~]# mysql
-------------------------------------------------总算是进来了--------------------------------
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 1
Server version: 5.5.16 Source distributionCopyright (c) 2000, 2011, 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> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| test |
+--------------------+
4 rows in set (0.00 sec)mysql>
4.1数据库的启动和关闭
CentOs6
# service mysqld start (5.0版本是mysqld)
# service mysql start (5.5.7版本是mysql)
CentOs7
[root@Mysql-Redis ~]# systemctl start mysql
[root@Mysql-Redis ~]# systemctl stop mysql
4.2 登录 mysql 删除无用配置
mysql> use mysql
Database changed
mysql> show tables;
+---------------------------+
| Tables_in_mysql |
+---------------------------+
| columns_priv |
| db |
| event |
| func |
| general_log |
| help_category |
| help_keyword |
| help_relation |
| help_topic |
| host |
| ndb_binlog_index |
| plugin |
| proc |
| procs_priv |
| proxies_priv |
| servers |
| slow_log |
| tables_priv |
| time_zone |
| time_zone_leap_second |
| time_zone_name |
| time_zone_transition |
| time_zone_transition_type |
| user |
+---------------------------+
24 rows in set (0.06 sec)
mysql> select user,host from user;
+------+-------------+
| user | host |
+------+-------------+
| root | 127.0.0.1 |
| root | ::1 |
| | Mysql-Redis |
| root | MysqlRedis |
| | localhost |
| root | localhost |
+------+-------------+
6 rows in set (0.01 sec)
mysql> delete from mysql.user where user='';
Query OK, 2 rows affected (0.00 sec)
mysql> delete from mysql.user where host='::1';
Query OK, 1 row affected (0.00 sec)
mysql> select user,host from user;
+------+-------------+
| user | host |
+------+-------------+
| root | 127.0.0.1 |
| root | Mysql-Redis |
| root | localhost |
+------+-------------+
3 rows in set (0.00 sec)
4.3 设置密码,授权登录
4.3.1 设置初始密码
[root@Mysql-Redis ~]# /usr/local/mysql/bin/mysqladmin -u root password '123456'
4.3.2修改密码
修改密码方式①
[root@Mysql-Redis ~]# /usr/local/mysql/bin/mysqladmin -u root -p 123456 password '123456'
修改密码方式②
(1)[root@Mysql-Redis ~]# vi /etc/my.cnf
在配置文件中找到 [mysqld] ,在这行下面添加 skip-grant-tables;
(2)重启数据库
(3)重启之后输入mysql即可进入mysql
(4)mysql> update user set password=password("你的新密码") where user="root";
mysql> flush privileges;
mysql> quit
(5)编辑my.cnf,去掉(或者注释掉)刚才添加的内容,然后重启MySQL
(6)[root@Mysql-Redis ~]# mysql -u root -p
Enter password:
输入刚才的密码,即可进入mysql。
5.windows系统,利用NavicatforMysql软件连接mysql
其实这里应该放在上节的来讲,作为授权的一部分,但是后来想想,既然打算延伸一下,就放在这里吧。
(1)先通过密码,进入数据库
(2)mysql> grant all privileges on *.* to 'root'@'%' identified by 'MysqlRedis' with grant option;
root 是指用户名称,MysqlRedis 是用户密码
这条命令的意思就是,所有用root用户登录的,都授权使用MysqlRedis这个密码;
(3)刷新一下数据库,mysql> flush privileges;
(4)这时,通过NavicatforMysql 测试,结果比较悲剧,(Can't connect to MySQL server on 'localhost')
这时并不是数据库本身的问题了,而是计算机防火墙,我把防火墙关一下,([root@Mysql-Redis ~]# systemctl stop firewalld)
你以为这样就结束了?
其实,关闭防火墙不是最终的办法,实际生产中,我们不能把整个服务器放在互联网当肉鸡,因此有必要设置防火墙策略,只暴露mysql数据库 3306端口就可以了。
6、防火墙设置
[root@Mysql-Redis ~]# firewall-cmd --zone=public --add-port=3306/tcp --permanent
success
[root@Mysql-Redis ~]# firewall-cmd --reload
success
7、免密登录
7.1 通过配置信息进入数据库
把数据库的相关个人配置保存在文件中
[root@Mysql-Redis ~]# cd tools/scripts/
[root@Mysql-Redis scripts]# vi .mysqlconfig
mysql -uroot -pMysqlRedis -h192.168.140.145
可以通过这配配置直接进入数据库
[root@Mysql-Redis ~]# mysql -uroot -pMysqlRedis -h192.168.140.145
7.2免密登录
(1)创建软连接
[root@Mysql-Redis ~]# ln -s /usr/local/mysql/bin/mysql tools/scripts/mysql
(2)进入数据库
(3)mysql> grant all privileges on *.* to 'root'@'localhost' identified by '' with grant option;
mysql> flush privileges;
(4)此时通过本地访问,已实现免密登录
[root@Mysql-Redis ~]# tools/scripts/mysql
之所以看得远,是因为站在巨人的肩膀上,感谢以下几位的文档。
https://www.cnblogs.com/lixuchun/p/9240888.html
https://blog.csdn.net/Soinice/article/details/93144618
https://blog.csdn.net/Mr_wangB0/article/details/102662583#commentBox