l源码安装mysql升级_[Linux]javaEE篇:源码安装mysql

javaEE :源码安装mysql

安装环境

系统平台:CentOS-7-x86_64

数据库版本:mysql-5.6.14

源码安装mysql步骤:

一、卸载mysql

安装mysql之前,先确保linux系统中没有mysql的相关文件;

如果没有,那么请忽略这一步的卸载过程。

如果有,那么把mysql卸载。

1、检查是否有myql service

rpm -qa | grep mysql:检查是否有mysql

2、如果有,卸载掉mysql

rpm -e mysql_libs==》rpm -e mysql具体包名:普通删除模式

或者

rpm -e --nodeps mysql_libs==》rpm -e --nodeps mysql具体包名:强力删除模式,如果使用上面命令删除时,提示有依赖的其它文件,则用该命令可以对其进行强力删除 。

二、安装mysql

1、安装编译代码需要的包

yum -y install make gcc-c++ cmake bison-devel ncurses-devel。直接将此指令复制粘贴执行。

2、下载MySQL ,并放到/usr/local目录下

省略此步骤

3、解压mysql源码包,并进入mysql目录中

tar xvf mysql-5.6.14.tar.gz:解压mysql源码包

cd /usr/local/mysql-5.6.14:进入到mysql目录下

4、编译安装

cmake -DCMAKE_INSTALL_PREFIX=/usr/local/mysql -DMYSQL_DATADIR=

/usr/local/mysql/data -DSYSCONFDIR=/etc -DWITH_MYISAM_STORAGE_ENGINE=

1 -DWITH_INNOBASE_STORAGE_ENGINE=1 -DWITH_MEMORY_STORAGE_ENGINE=

1 -DWITH_READLINE=1 -DMYSQL_UNIX_ADDR=

/var/lib/mysql/mysql.sock -DMYSQL_TCP_PORT=3306 -DENABLED_LOCAL_INFILE=

1 -DWITH_PARTITION_STORAGE_ENGINE=1 -DEXTRA_CHARSETS=

all -DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_general_ci

复制上面这段指令,在/usr/local/mysql-5.6.14 (进入到mysql目录下)执行这段指令。

执行完成后,再执行下面的这个指令:

make && make install

make && make install:编译并安装;&&表示执行完前面的这段指令,再执行后面的这个安装指令。

这个一步大约需要半个小时。安装完成,接下来就需要来配置我们的mysql了。

三、配置mysql

在设置权限之前,我们要先确定linux系统中是否有mysql用户及用户组

cat /etc/passwd:查看用户列表

cat /etc/group:查看用户组列表

如果没有就进行创建mysql用户及mysql用户组

groupadd mysql:创建mysql用户组

useradd -g mysql mysql:创建mysql用户,并设置这个用户为mysql组。

下面就正式进入到:设置权限

1、设置权限

在设置mysql权限之前,我们先来查询一下这个文件的信息

[root@localhost local]# ls -l | grep mysql

drwxr-xr-x. 13 root root 213 May 5 00:15 mysql

chown -R mysql:mysql /usr/local/mysql:修改/user/local/mysql的权限

修改完权限,重新查看一下mysql的信息

[root@localhost local]# ls -l | grep mysql

drwxr-xr-x. 13 mysql mysql 213 May 5 00:17 mysql

修改权限成功!!

2、初始化配置

进入到安装路径(并执行下面的这段指令),执行初始化配置脚本,创建系统自带的数据库和表。

cd /usr/local/mysql:进入到安装路径

scripts/mysql_install_db --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data --user=mysql:这是一条指令

注意:执行上面这条指令报错

WARNING: Default config file /etc/my.cnf exists on the system

This file will be read by default by the MySQL server

If you do not want to use this, either remove it, or use the

--defaults-file argument to mysqld_safe when starting the server

报错原因:在CentOS 7版操作系统的最小安装完成后,在/etc目录下会存在一个my.cnf,需要将此文件更名为其他的名字,如:/etc/my.cnf.bak,否则,该文件会干扰源码安装的MySQL的正确配置,造成无法启动。修改名称,防止干扰:

解决方法:mv /etc/my.cnf /etc/my.cnf.bak

注:在启动MySQL服务时,会按照一定次序搜索my.cnf,先在/etc目录下找,找不到则会搜索"$basedir/my.cnf",在本例中就是 /usr/local/mysql/my.cnf,这是新版MySQL的配置文件的默认位置!

三、启动mysql

添加服务,拷贝服务脚本到init.d目录,并设置开启启动。

注意:是在/usr/local/mysql下执行的

shell

[root@localhost ~]# cd /usr/local/mysql

[root@localhost mysql]# cp support-files/mysql.server /etc/init.d/mysql

[root@localhost mysql]# chkconfig mysql on

[root@localhost mysql]# service mysql start

Starting MySQL.. SUCCESS!

上面是的指令就是启动mysql所用到的;

第一行:进入到/usr/local/mysql目录下;

第二行:拷贝服务脚本到init.d目录;

第三行:设置开机启动;

第四行:启动Mysql

四、使用mysql

执行下面的命令,进行修改密码:

[root@localhost mysql]# cd /usr/local/mysql/bin

[root@localhost bin]# ./mysql -uroot

Welcome to the MySQL monitor. Commands end with ; or \g.

Your MySQL connection id is 1

Server version: 5.6.14 Source distribution

Copyright (c) 2000, 2013, 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> set password =password('root');

Query OK, 0 rows affected (0.01 sec)

mysql> quit //退出指令

Bye

[root@localhost bin]# ./mysql -uroot

ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)

[root@localhost bin]# ./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.6.14 Source distribution

Copyright (c) 2000, 2013, 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; // 查看mysql中数据库

+--------------------+

| Database |

+--------------------+

| information_schema |

| mysql |

| performance_schema |

| test |

+--------------------+

4 rows in set (0.03 sec)

mysql>

第一行:cd /usr/local/mysql/bin,进入该目录

第二行:./mysql -uroot

第十一行:set password =password('root');:修改数据库密码

第十三行:quit;退出

第十七行:./mysql -u root -p;重新登录mysql,输入密码

第 三十一 行:show databases;查看mysql中数据库

接着在上面的基础上,来创建一张user表,并插入两条数据

mysql> create database myDB; //创建数据库:myDB

Query OK, 1 row affected (0.00 sec)

mysql> use myDB; //使用数据库:myDB

Database changed

mysql> show databases; //查询列出所有数据库

+--------------------+

| Database |

+--------------------+

| information_schema |

| myDB |

| mysql |

| performance_schema |

| test |

+--------------------+

5 rows in set (0.00 sec)

mysql> create table user(id int, name varchar(32)); //创建表:user

Query OK, 0 rows affected (0.01 sec)

mysql> insert into user values(100,'tom'); //插入数据:user

Query OK, 1 row affected (0.00 sec)

mysql> insert into user values(1,'tom');

Query OK, 1 row affected (0.00 sec)

mysql> insert into user values(2,'王春兰');

Query OK, 1 row affected (0.00 sec)

mysql> select * from user; //查询user表

+------+-----------+

| id | name |

+------+-----------+

| 100 | tom |

| 1 | tom |

| 2 | 王春兰 |

+------+-----------+

3 rows in set (0.00 sec)

mysql>

五、配置全部变量

!!!重要

将/usr/local/mysql/bin目录配置到全局变量的文件中去/etc/profile;

[root@localhost mysql]# pwd

/usr/local/mysql

[root@localhost mysql]# vim /etc/profile

//... ...省略部分内容

unset i

unset -f pathmunge

JAVA_HOME=/usr/local/java

// 注意将:/usr/local/mysql/bin配置到这来,前面用:隔开

PATH=$PATH:$JAVA_HOME/bin:/usr/local/mysql/bin

CLASSPATH=$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar

export JAVA_HOME PATH CLASSPATH

最后重启服务 或者退出重新登录

systemctl daemon-reload:服务重载

logout:退出

这时候我们就可以在任意位置登录mysql了。

[root@localhost ~]# mysql -u root -p

Enter password:

Welcome to the MySQL monitor. Commands end with ; or \g.

Your MySQL connection id is 5

Server version: 5.6.14 Source distribution

Copyright (c) 2000, 2013, 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>

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值