wns9778.com_威尼斯wns.9778官网

热门关键词: wns9778.com,威尼斯wns.9778官网
wns9778.com > 计算机教程 > 【wns9778.com】LNMP编译安装之mysql安装--图文详解

原标题:【wns9778.com】LNMP编译安装之mysql安装--图文详解

浏览次数:198 时间:2019-05-11

三 步骤3:  

  安装mysql,使用 --initialize,basedir 基础目录,datadir 为数据目录。

[root@hsr ~]# cd /usr/local/mysql/mysql-5.7.23-linux-glibc2.12-x86_64/bin
[root@hsr bin]# ./mysqld  --initialize --user=mysql --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data
2018-08-23T06:56:21.157088Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2018-08-23T06:56:21.157246Z 0 [ERROR] Can't find error-message file '/usr/local/mysql/share/errmsg.sys'. Check error-message file location and 'lc-messages-dir' configuration directive.
2018-08-23T06:56:26.287087Z 0 [Warning] InnoDB: New log files created, LSN=45790
2018-08-23T06:56:27.059913Z 0 [Warning] InnoDB: Creating foreign key constraint system tables.
2018-08-23T06:56:27.138616Z 0 [Warning] No existing UUID has been found, so we assume that this is the first time that this server has been started. Generating a new UUID: a7e28575-a6a1-11e8-af13-000c29affb65.
2018-08-23T06:56:27.154064Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened.
2018-08-23T06:56:27.155635Z 1 [Note] A temporary password is generated for root@localhost: ro0ssOGT?ocf

LNMP编译安装之mysql安装--图文详解

1、前言

本次安装采用源码安装,主要资源包从官网下载,次要依赖则使用yum进行安装,本篇只涉及mysql的安装,msyql远程登录,不涉及mysql具体配置。该教程纯属安装,不涉及任何重要知识点,老少皆宜。

2、安装步骤

2.1、下载boost(只下载不安装)

wget http://nchc.dl.sourceforge.net/project/boost/boost/1.59.0/boost_1_59_0.tar.gz

wns9778.com 1

2.2、解压bosot

tar zxvf  boost_1_59_0.tar.gz 

wns9778.com 2

2.3、移动boost(可以省略)

mv boost_1_59_0  /usr/local/boost(目录位置需要记录,安装mysql需要使用)

wns9778.com 3

2.4、下载mysql

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

wns9778.com 4

2.5、解压msyql

tar -zxvf mysql-5.7.18.tar.gz

wns9778.com 5

2.6、安装依赖

yum install gcc-c ncurses-devel perl-Data-Dumper

wns9778.com 6

3、安装前的准备工作

3.1、创建用户

useradd -M -s /sbin/nologin mysql

wns9778.com 7

3.2、创建目录

mkdir -pv /usr/local/mysql/mydata

mkdir -pv /usr/local/mysql/conf

wns9778.com 8

3.3、修改目录拥有者

chown -R mysql /usr/local/mysql

wns9778.com 9

3.4、删除my.cnf

rm -rf /etc/my.cnf(必须删除my.cnf,不删经常不成功)

wns9778.com 10

4、开始安装

4.1、生成makefile文件

cd mysql-5.7.19

cmake
-DCMAKE_INSTALL_PREFIX=/usr/local/mysql  (安装目录)
-DMYSQL_DATADIR=/usr/local/mysql/mydata     (存储目录)
-DSYSCONFDIR=/usr/local/mysql/conf  (配置文件目录)
-DMYSQL_USER=mysql  (用户)
-DWITH_MYISAM_STORAGE_ENGINE=1
-DWITH_INNOBASE_STORAGE_ENGINE=1
-DWITH_ARCHIVE_STORAGE_ENGINE=1
-DWITH_MEMORY_STORAGE_ENGINE=1
-DWITH_READLINE=1
-DMYSQL_UNIX_ADDR=/usr/local/mysql/mysql.sock  (UNIX socket文件)
-DMYSQL_TCP_PORT=3306
-DENABLED_LOCAL_INFILE=1
-DENABLE_DOWNLOADS=1
-DWITH_PARTITION_STORAGE_ENGINE=1
-DEXTRA_CHARSETS=all
-DDEFAULT_CHARSET=utf8
-DDEFAULT_COLLATION=utf8_general_ci
-DWITH_DEBUG=0
-DMYSQL_MAINTAINER_MODE=0
-DWITH_SSL:STRING=bundled
-DWITH_ZLIB:STRING=bundled
-DDOWNLOAD_BOOST=1
-DWITH_BOOST=/usr/local/boost (boost目录)
wns9778.com 11

make完成

wns9778.com 12

4.2、编译安装

 

make && make install

wns9778.com 13

安装完成

wns9778.com 14

4.3、初始化

/usr/local/mysql/bin/mysqld --initialize --user=mysql --basedir=/usr/local/mysql --datadir=/usr/local/mysql/mydata(随机密码初始化)
/usr/local/mysql/bin/mysqld --initialize-insecure --user=mysql --basedir=/usr/local/mysql --datadir=/usr/local/mysql/mydata(无密码初始化)

注:两个目录需要根据makefile的目录填写
本次采用无密码初始化

wns9778.com 15

4.4、启动mysql实例

wns9778.com 16

启动成功后,需要重开一个控制台进行登录操作

/usr/local/mysql/bin/mysql -u root -p

wns9778.com 17

5、进行远程登录帐号创建

5.1、创建登录帐号

GRANT ALL PRIVILEGES ON *.* TO 'mysql_user(帐号)'@'%(host)' IDENTIFIED BY 'mysql_user(密码)' WITH GRANT OPTION;

wns9778.com 18

5.2、开放330端口

firewall-cmd --zone=public --add-port=3306/tcp --permanent

wns9778.com 19

5.3、重启防火墙

systemctl restart firewalld.service

wns9778.com 20

5.4、远程登录测试

6、修改环境变量文件

vi /etc/profile ;

wns9778.com 21

底部添加一行

wns9778.com 22

刷新环境变量文件

source /etc/profile

wns9778.com 23

重新登录测试

wns9778.com 24

7、开启自启设置

7.1、复制驱动文件

cp /usr/local/mysql/support-files/mysql.server  /etc/init.d/mysqld

wns9778.com 25

7.2、修改文件权限

chmod x /etc/init.d/mysqld

wns9778.com 26

chkconfig --add mysqld

wns9778.com 27

chkconfig mysqld on

wns9778.com 28

7.3、重启测试

8、配置my.cnf文件

mysql 5.7版本以上默认不会产生my.cnf文件,需要手动创建,本次以开启二进制文件为例设置my.cnf文件

8.1、创建my.cnf

vi  /etc/my.cnf

wns9778.com 29

在文件中添加以下几行

[mysqld]
server-id = 1(这个要写,不写开不起来)
log-bin = bin.log
wns9778.com 30

8.2、登录mysql查询二进制日志开启状态

mysql> SHOW VARIABLES LIKE 'log_%';

 

wns9778.com 31

 八. 设置密码  

  8.1 打开my.cnf文件,添加skip-grant-tables,来重置密码,如下所示
    wns9778.com 32
  8.2 启动服务,再次登录,在输入密码处按回车键进入。

[root@hsr ~]# vim /etc/my.cnf
[root@hsr ~]# service mysql restart
Shutting down MySQL.. SUCCESS! 
Starting MySQL. SUCCESS! 
[root@hsr ~]# mysql -u root -p
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or g.
Your MySQL connection id is 2
Server version: 5.7.23

  8.3 进入mysql后,修改密码

mysql> use mysql;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A

Database changed

mysql> update user set authentication_string=password('123456') where user='root';
Query OK, 1 row affected, 1 warning (0.00 sec)
Rows matched: 1  Changed: 1  Warnings: 1

  退出mysql>quit;  编辑 my.cnf 注释掉#skip-grant-tables

 8.4 重启mysql服务,输入修改后的密码(123456)进入

[root@hsr ~]# service mysql restart
Shutting down MySQL.. SUCCESS! 
Starting MySQL. SUCCESS! 
[root@hsr ~]# mysql -u root -p
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or g.
Your MySQL connection id is 2
Server version: 5.7.23

四步骤4:

  4.1 创建RSA private key。

[root@hsr bin]# bin/mysql_ssl_rsa_setup --datadir=/usr/local/mysql/data

  wns9778.com 33

  4.2 修改当前目录拥有者为 root 用户,修改data 目录拥有者为 mysql

[root@hsr bin]# chown -R root:root /usr/local/mysql
[root@hsr bin]# chown -R mysql:mysql /usr/local/mysql/data

 六.步骤6 启动mysql

[root@hsr bin]# service mysql start
/etc/init.d/mysql: line 239: my_print_defaults: command not found
    Starting MySQL ERROR! Couldn't find MySQL server (/usr/local/mysql/bin/mysqld_safe) 

--提示未找到路径,需要把"mysql-5.7.23-linux-glibc2.12-x86_64" 文件夹去掉,使用mv 将里面的文件移到/usr/locl/mysql下,共9个文件
[root@hsr bin]# mv /usr/local/mysql/mysql-5.7.23-linux-glibc2.12-x86_64/README /usr/local/mysql
[root@hsr bin]# mv /usr/local/mysql/mysql-5.7.23-linux-glibc2.12-x86_64/COPYING /usr/local/mysql
[root@hsr bin]# mv /usr/local/mysql/mysql-5.7.23-linux-glibc2.12-x86_64/support-files /usr/local/mysql
[root@hsr bin]# mv /usr/local/mysql/mysql-5.7.23-linux-glibc2.12-x86_64/share /usr/local/mysql
[root@hsr bin]# mv /usr/local/mysql/mysql-5.7.23-linux-glibc2.12-x86_64/man /usr/local/mysql
[root@hsr bin]# mv /usr/local/mysql/mysql-5.7.23-linux-glibc2.12-x86_64/lib /usr/local/mysql
[root@hsr bin]# mv /usr/local/mysql/mysql-5.7.23-linux-glibc2.12-x86_64/include /usr/local/mysql
[root@hsr bin]# mv /usr/local/mysql/mysql-5.7.23-linux-glibc2.12-x86_64/docs /usr/local/mysql
[root@hsr bin]# mv /usr/local/mysql/mysql-5.7.23-linux-glibc2.12-x86_64/bin /usr/local/mysql

-- 再启动
[root@hsr bin]# service mysql start
Starting MySQL.2018-08-24T01:06:20.545225Z mysqld_safe error: log-error set to '/var/log/mariadb/mariadb.log', however file don't exists. Create writable for user 'mysql'.
 ERROR! The server quit without updating PID file (/usr/local/mysql/data/hsr.pid).

-- 提示/var/log/mariadb/mariadb.log 不存在, 打开my.cnf 能看到定义的默认路径
[mysqld_safe]
log-error=/var/log/mariadb/mariadb.log
pid-file=/var/run/mariadb/mariadb.pid

--创建目录 给权限
[root@hsr bin]# mkdir /var/log/mariadb 
[root@hsr bin]# touch /var/log/mariadb/mariadb.log 
[root@hsr bin]# chown -R mysql:mysql  /var/log/mariadb/

-- 再启动
[root@hsr bin]# service mysql start
Starting MySQL.... ERROR! The server quit without updating PID file (/usr/local/mysql/data/hsr.pid).

-- 错误信息是hsr.pid进程出问题,先查看下日志
[root@hsr ~]# cat /var/log/mariadb/mariadb.log

  wns9778.com 34
   在my.cnf中注释上面参数(#chkconfig --level 35 mysqld on),再启动
  wns9778.com 35
  上图意思是不能创建mysql.sock.lock 文件,一般是权限不足,如下设置好权限,启动成功
  wns9778.com 36

 五.步骤5 配置mysql(mysql.server)和my.cnf文件

--检查 etc/my.cnf文件是否存在 (二进制安装,默认配置文件在/etc/my.cnf)
    [root@hsr etc]# find -name  my.cnf
    ./my.cnf

 --将support-files 目录下的mysql.server文件复制到etc/init.d下
    [root@hsr ~]# cd /usr/local/mysql/mysql-5.7.23-linux-glibc2.12-x86_64/support-files
    [root@hsr support-files]# cp mysql.server /etc/init.d/mysql

 -- 配置/etc/init.d/mysql服务文件 添加basedir和datadir
    [root@hsr support-files]# vim /etc/init.d/mysql

    wns9778.com 37

   修改my.cnf  配置以下四个参数(wns9778.com,注意:chkconfig -- level 35 mysqld on 不要加上,后面报错,又得去掉)
    wns9778.com 38

本文由wns9778.com发布于计算机教程,转载请注明出处:【wns9778.com】LNMP编译安装之mysql安装--图文详解

关键词: wns9778.com

上一篇:wns9778.com:Celery 框架学习笔记(生产者消费者模式

下一篇:没有了