编译安装mysql

1.从官网下载tar包:

wget https://dev.mysql.com/get/Downloads/MySQL-5.7/mysql-boost-5.7.27.tar.gz

2.导包

rz

之后查询 ll    。和之前一样,你在哪个路径下导的包 它就在哪。

3.解压

[root@localhost ~]#  tar xf mysql-boost-5.7.27.tar.gz

4.进入

[root@localhost ~]# cd mysql-boost-5.7.27/

5.清理安装环境

# yum erase mariadb mariadb-server mariadb-libs mariadb-devel -y
# rm -rf /etc/my*
#  rm -rf /var/lib/mysql

6.添加用户   

-M 不创建用户的家目录

 # useradd -r mysql -M -s /bin/nologin

7.安装编译工具

# yum -y install ncurses ncurses-devel openssl-devel bison gcc gcc-c++ make glibc automake autoconf
# yum -y install cmake

8.编译安装

[root@mysql-server mysql-5.7.27]# cmake . \
-DWITH_BOOST=boost/boost_1_59_0/ \
-DCMAKE_INSTALL_PREFIX=/usr/local/mysql \
-DSYSCONFDIR=/etc \
-DMYSQL_DATADIR=/usr/local/mysql/data \
-DINSTALL_MANDIR=/usr/share/man \
-DMYSQL_TCP_PORT=3306 \
-DMYSQL_UNIX_ADDR=/tmp/mysql.sock \
-DDEFAULT_CHARSET=utf8 \
-DEXTRA_CHARSETS=all \
-DDEFAULT_COLLATION=utf8_general_ci \
-DWITH_READLINE=1 \
-DWITH_SSL=system \
-DWITH_EMBEDDED_SERVER=1 \
-DENABLED_LOCAL_INFILE=1 \
-DWITH_INNOBASE_STORAGE_ENGINE=1

ehco $?   查看上条命令 是否执行成功。

然后执行这条命令  (make和马克 make  install可以同时执行也可以分开执行)需要长时间等待

[root@mysql-server mysql-5.7.27]# make && make install

9.初始化

[root@mysql-server mysql-5.7.27]# cd /usr/local/mysql
[root@mysql-server mysql]# chown -R mysql.mysql .
[root@mysql-server mysql]# ./bin/mysqld --initialize --user=mysql --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data 

要记住最后的登录密码  (密码是无规则的)复制粘贴。初始化只需要初始化一次。

 10.设置环境变量

[root@localhost mysql]# echo 'export PATH=/usr/local/mysql/bin:$PATH' >>/etc/profile
[root@localhost mysql]# source /etc/profile

通过使用source命令加上路径,可以在当前shell环境中加载并执行指定的脚本文件。这对于设置环境变量、导入函数和配置文件等操作非常有用。

[root@localhost mysql]# echo $PATH
/usr/local/mysql/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin
[root@mysql-server ~]# vim /etc/my.cnf

-如果打开文件有内容将文件中所有内容注释掉,在添加如下内容

记得将代码敲全或者复制粘贴完 瞅一瞅。看有没有错误  本人就是眼瞎没瞅 代码没敲全,后面报错 找了老半天!!!!
 
[client]
port = 3306
socket = /tmp/mysql.sock
default-character-set = utf8

[mysqld]
port = 3306
user = mysql
basedir = /usr/local/mysql        #指定安装目录
datadir = /usr/local/mysql/data        #指定数据存放目录
socket = /tmp/mysql.sock
character_set_server = utf8

11.启动mysql

[root@mysql-server ~]# cd /usr/local/mysql
[root@mysql-server mysql]# ./bin/mysqld_safe --user=mysql &

12.登录mysql

[root@mysql-server mysql]# /usr/local/mysql/bin/mysql -uroot -p'GP9TKGgY9i/8'

这是上条命令输入后,输出的结果

mysql: [Warning] Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.7.27

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

退出:  exit         \q  都可以

mysql> exit

13.systemctl启动方式

拷贝启动脚本到/etc/init.d/目录下,并改名mysqld

[root@qfedu.com mysql]# cp support-files/mysql.server /etc/init.d/mysqld
[root@qfedu.com mysql]# ls -l /etc/init.d/mysqld
-rwxr-xr-x 1 root root 10588 Aug 1 18:33 /etc/init.d/mysqld

重新加载系统服务

[root@localhost mysql]# systemctl daemon-reload

启动MySQL数据库,并检查端口监听状态

[root@localhost mysql]# systemctl start mysqld  --启动mysqld
Starting MySQL. SUCCESS! 
[root@localhost ~]# ps -ef | grep mysql
root      39453      1  0 18:29 ?        00:00:00 /bin/sh /usr/local/mysql/bin/mysqld_safe --datadir=/usr/local/mysql/data --pid-file=/usr/local/mysql/data/localhost.localdomain.pid
mysql     39638  39453  0 18:29 ?        00:00:02 /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=localhost.localdomain.err --pid-file=/usr/local/mysql/data/localhost.localdomain.pid --socket=/tmp/mysql.sock --port=3306
root      88506   1426  0 21:04 pts/0    00:00:00 grep --color=auto mysql

14.数据库修改密码

[root@localhost ~]#/usr/local/mysql/bin/mysqladmin -uroot -p'原密码'  passwd '新密码'

15.登录mysql

[root@localhost ~]# mysql -p'密码'

成功页面

mysql: [Warning] Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 6
Server version: 5.7.27 Source distribution

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

附加:创建一个新库

首先查询mysql的库

mysql> show databases;




+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| performance_schema |
| sys                |
| zhouyq             |
+--------------------+
5 rows in set (0.00 sec)

第一行是输入的命令,下面图形里是mysql的库。在MySQL中输入命令结尾需要加  ;

创建一个新库 

mysql> create database 名字 ;

最后再次查询即可。

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值