首页 技术 正文
技术 2022年11月20日
0 收藏 644 点赞 4,047 浏览 3961 个字

本次mysql数据库安装采用二进制安装(免安装即绿色版),数据库版本是mysql5.7.26

 首先下载mysql安装包,然后上传服务器里,最后解压。

  卸载centos7自带的数据库软件包:

    [root@localhost mysql]# yum remove mariadb

 开始安装mysql:

  [root@localhost tools]# ll
  total 629756
  -rw-r–r– 1 root root 644869837 Dec 11 15:35 mysql-5.7.26-linux-glibc2.12-x86_64.tar.gz

  [root@localhost tools]# tar xf mysql-5.7.26-linux-glibc2.12-x86_64.tar.gz

  [root@localhost tools]# mv mysql-5.7.26-linux-glibc2.12-x86_64 /application/mysql

  [root@localhost ~]# useradd -s /sbin/nologin mysql

    把如下内容太添加到/etc/profile末尾行,然后执行命令使生效:

      export PATH=/application/mysql/bin:$PATH

      [root@localhost ~]# source /etc/profile

    查看是否生效,使用命令查看Mysql版本:   

      [root@localhost ~]# mysql -V
      mysql Ver 14.14 Distrib 5.7.26, for linux-glibc2.12 (x86_64) using EditLine wrapper

    授权:

    [root@localhost ~]# chown -R mysql.mysql /application/*
    [root@localhost ~]# chown -R mysql.mysql /data

    初始化数据方式一:密码设置比较复杂

      创建mysql数据目录:

        [root@localhost ~]# mkdir /data/mysql/data -p

        [root@localhost ~]# chown -R mysql.mysql /data 

      注意:mysql错误日志默认在数据目录里,默认是主机名.err!!!

[root@localhost ~]# mysqld –initialize –user=mysql –basedir=/application/mysql –datadir=/data/mysql/data

2019-12-12T02:09:08.794620Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use –explicit_defaults_for_timestamp server option (see documentation for more details).
2019-12-12T02:09:12.036238Z 0 [Warning] InnoDB: New log files created, LSN=45790
2019-12-12T02:09:12.283068Z 0 [Warning] InnoDB: Creating foreign key constraint system tables.
2019-12-12T02:09:12.346261Z 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: 63c6e908-1c84-11ea-9a0c-000c29002b3d.
2019-12-12T02:09:12.693297Z 0 [Warning] Gtid table is not ready to be used. Table ‘mysql.gtid_executed’ cannot be opened.
2019-12-12T02:09:12.697614Z 1 [Note] A temporary password is generated for root@localhost: #vVZul3CIt_f

    初始化数据方式二:密码设置简便      

[root@localhost ~]# rm -rf /data/mysql/data/*
[root@localhost ~]# mysqld –initialize-insecure –user=mysql –basedir=/application/mysql –datadir=/data/mysql/data
2019-12-12T03:04:10.776764Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use –explicit_defaults_for_timestamp server option (see documentation for more details).
2019-12-12T03:04:12.401550Z 0 [Warning] InnoDB: New log files created, LSN=45790
2019-12-12T03:04:12.571184Z 0 [Warning] InnoDB: Creating foreign key constraint system tables.
2019-12-12T03:04:12.637140Z 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: 12e75191-1c8c-11ea-a008-000c29002b3d.
2019-12-12T03:04:12.640047Z 0 [Warning] Gtid table is not ready to be used. Table ‘mysql.gtid_executed’ cannot be opened.
2019-12-12T03:04:12.643946Z 1 [Warning] root@localhost is created with an empty password ! Please consider switching off the –initialize-insecure option.

   配置mysql配置文件: 

[root@localhost data]# cp /etc/my.cnf /tmp/my.cnf20191212bak

[root@localhost data]# >/etc/my.cnf   

[root@localhost data]# cat >> /etc/my.cnf<< EOF
 [mysqld]
 user=mysql
 basedir=/application/mysql
datadir=/data/mysql/data
 socket=/tmp/mysql.sock
 server_id=6
 port=3306
 [mysql]
 socket=/tmp/mysql.sock
> EOF

   启动mysql数据库:centos7启动mysql数据库有两种方式

      方式1:      

[root@localhost ~]# cp /application/mysql/support-files/mysql.server /etc/init.d/mysqld
[root@localhost ~]# service mysqld status
ERROR! MySQL is not running
[root@localhost ~]# service mysqld start
Starting MySQL.Logging to ‘/data/mysql/data/localhost.localdomain.err’.
. SUCCESS!

      方式2:编辑如下配置文件

[root@localhost ~]# more /usr/lib/systemd/system/mysqld.service
[Unit]
Description=MySQL Server
Documentation=man:mysqld(8)
Documentation=http://dev.mysql.com/doc/refman/en/using-systemd.html
After=network.target
After=syslog.target
[Install]
WantedBy=multi-user.target
[Service]
User=mysql
Group=mysql
ExecStart=/application/mysql/bin/mysqld –defaults-file=/etc/my.cnf

  启动mysql:

  [root@localhost ~]# systemctl start mysqld.service

  [root@localhost ~]# netstat -lnp |grep 3306
  tcp6 0 0 :::3306 :::* LISTEN 25994/mysqld

如何修改mysql 管理员(root)用户密码:

  [root@localhost ~]# mysqladmin -uroot -p password xxxxxxxxxx

  然后直接回车就OK了!

   

相关推荐
python开发_常用的python模块及安装方法
adodb:我们领导推荐的数据库连接组件bsddb3:BerkeleyDB的连接组件Cheetah-1.0:我比较喜欢这个版本的cheeta…
日期:2022-11-24 点赞:878 阅读:9,491
Educational Codeforces Round 11 C. Hard Process 二分
C. Hard Process题目连接:http://www.codeforces.com/contest/660/problem/CDes…
日期:2022-11-24 点赞:807 阅读:5,907
下载Ubuntn 17.04 内核源代码
zengkefu@server1:/usr/src$ uname -aLinux server1 4.10.0-19-generic #21…
日期:2022-11-24 点赞:569 阅读:6,740
可用Active Desktop Calendar V7.86 注册码序列号
可用Active Desktop Calendar V7.86 注册码序列号Name: www.greendown.cn Code: &nb…
日期:2022-11-24 点赞:733 阅读:6,493
Android调用系统相机、自定义相机、处理大图片
Android调用系统相机和自定义相机实例本博文主要是介绍了android上使用相机进行拍照并显示的两种方式,并且由于涉及到要把拍到的照片显…
日期:2022-11-24 点赞:512 阅读:8,132
Struts的使用
一、Struts2的获取  Struts的官方网站为:http://struts.apache.org/  下载完Struts2的jar包,…
日期:2022-11-24 点赞:671 阅读:5,294