MYSQL数据的安装、配置

---恢复内容开始---

linux安装mysql服务分两种安装方法:

  1、源码安装,优点是安装包比较小,只有十多M,缺点是安装依赖的库多,安装编译时间长,安装步骤复杂容易出错。

  2、使用官方编译好的二进制文件安装,优点是安装速度快,安装步骤简单,缺点是安装包很大,376M左右。我这里官方编译好的Linux二进制包安装mysql。

(记的第一次安装MYSQL是在学习Hadoop的时候,部署Hive,用到了,再往后就没有用过MYSQL一直用的Oracle,这一次几方面原因,再次安装Mysql,记录下来过程,最主要的是自己电脑上的内容太多,又不是连续操作,怕忘记端口、密码等等,顺便学习Python操作Mysql时用。)

一、软件下载

  到mysql官网下载mysql编译好的二进制安装包,在下载页面Select Platform:选项选择linux-generic,然后把页面拉到底部,64位系统下载Linux - Generic (glibc 2.5) (x86, 64-bit)。

  地址:https://dev.mysql.com/downloads/mysql/

  

  软件包上传、解压步骤略......

二、安装环境检查(初次安装可忽略)

  1.检查是否有rpm包,如果没有用rpm安装过mysql,不应该有残留,如果有,需要删掉

    检查语法: rpm -qa|grep -i mysql

    删除语法: rpm -e <包的名字>

    如果遇到依赖,无法删除,使用 rpm -e --nodeps <包的名字> 不检查依赖,直接删除rpm包。

  2.卸载系统自带的mariadb

    检查语法: rpm -qa|grep Mariadb

    删除语法: rpm -e <包的名字>

  3.查看所有的 mysql目录 ,并删除

    find / -name mysql

三、安装

  1.创建mysql用户组和mysql用户

    groupadd  mysql                                         //创建mysql 用户组

    useradd -g mysql mysql                             //创建一个用户名为mysql的用户并加入mysql用户组

  2.通过ssh工具,将MySQL安装包 mysql-8.0.13-linux-glibc2.12-x86_64.tar.xz 拖拽到 /software目录下并解压

    解压指令tar -xvf mysql-8.0.13-linux-glibc2.12-x86_64.tar.xz

    3.将解压后的安装包复制到/opt 目录下,并重命名mysql

    cp -Rf mysql-8.0.13-linux-glibc2.12-x86_64 /opt/mysql

  4.修改权限

    cd /opt/mysql

    chown –R mysql                       //把当前目录下的文件及目录的属性改为mysql用户

    chgrp –R mysql                     //把当前目录下的文件所属的组件改为mysql组

  5.创建data目录,作为数据库存储位置

    mkdir /opt/mysql/data

  6.配置my.cnf文件

    此文件非常重要,初始化之前一定要把此文件放到 /etc 目录下,

    此文件内容如下(路径根据自己的实际情况):

[[email protected] mysql]# vim /etc/my.cnf添加/修改如下:[client]
  port = 3306
  socket = /tmp/mysql.sock
[mysqld]
  character_set_server=utf8
  init_connect=‘SET NAMES utf8‘
  basedir=/opt/mysql
  datadir=/opt/mysql/data
  socket=/tmp/mysql.sock

  7.初始化mysql

    /opt/mysql/bin/mysqld --initialize --user=mysql --basedir=/opt/mysql --datadir=/opt/mysql/data

[[email protected] opt]# /opt/mysql/bin/mysqld --initialize --user=mysql --basedir=/opt/mysql --datadir=/opt/mysql/data2018-11-23T05:37:20.419244Z 0 [Warning] [MY-011070] [Server] ‘Disabling symbolic links using --skip-symbolic-links (or equivalent) is the default.                   Consider not using this option as it‘ is deprecated and will be removed in a future release.2018-11-23T05:37:20.435233Z 0 [System] [MY-013169] [Server] /opt/mysql/bin/mysqld (mysqld 8.0.13) initializing of server in progress as process 180272018-11-23T05:37:20.456938Z 0 [Warning] [MY-013242] [Server] --character-set-server: ‘utf8‘ is currently an alias for the character set UTF8MB3,                   but will be an alias for UTF8MB4 in a future release. Please consider using UTF8MB4 in order to be unambiguous.2018-11-23T05:37:23.561315Z 5 [Note] [MY-010454] [Server] A temporary password is generated for [email protected]: ti_g<4t/ZvcC2018-11-23T05:37:25.859931Z 0 [System] [MY-013170] [Server] /opt/mysql/bin/mysqld (mysqld 8.0.13) initializing of server has completed[[email protected] opt]#

    注意:把初始密码拷贝下来,备份

    chown -R root .  //把当前目录下的文件及目录的属性改为root 用户
    chown -R mysql data

四、启动并检查

  1.启动mysql,并查看是否已经启动成功

    /opt/mysql/bin/mysqld_safe --user=mysql &

[[email protected] opt]# /opt/mysql/bin/mysqld_safe --user=mysql &
[1] 8875
[[email protected] opt]# 2018-11-23T03:42:59.200011Z mysqld_safe Logging to ‘/var/log/mysqld.log‘.
2018-11-23T03:42:59.240320Z mysqld_safe Starting mysqld daemon with databases from /opt/mysql/data

  中间启动失败了。错误如下:

[[email protected] opt]# 2018-11-23T03:40:45.579575Z mysqld_safe Logging to ‘/var/log/mysqld.log‘.
2018-11-23T03:40:45.616041Z mysqld_safe Starting mysqld daemon with databases from /opt/mysql/data
2018-11-23T03:40:48.237984Z mysqld_safe mysqld from pid file /var/run/mysqld/mysqld.pid ended

  原因为:socket的路径mysql用户没有write的权限。报错如下:

2018-11-23T03:38:19.746257Z 0 [ERROR] [MY-013129] [Server] A message intended for a client cannot be sent there as no client-session is attached.             Therefore, we‘re sending the information to the error-log instead: MY-000001 - Can‘t create/write to file ‘/var/run/mysqld/mysqld.pid‘             (OS errno 13 - Permission denied)
2018-11-23T03:38:19.746285Z 0 [ERROR] [MY-010092] [Server] Can‘t start server: can‘t create PID file: Permission denied

  对该路径修改所属合写入权限:

[[email protected] mysql]# chown -Rf mysql.mysql  /var/run/mysqld
[[email protected] mysql]# chmod 775  /var/run/mysqld

  2.通过初始密码登录mysql,并修改密码

    /opt/mysql/bin/mysqladmin -uroot -p password

    -----这里有问题一直登录不上,后面解决。

  3.设置开机自启

cp /opt/mysql/support-files/mysql.server  /etc/rc.d/init.d/mysqld
chmod +x /etc/rc.d/init.d/mysqld
chkconfig  --add mysqld
chkconfig  --list mysqld
[[email protected] opt]# cp /opt/mysql/support-files/mysql.server  /etc/rc.d/init.d/mysql
[[email protected] opt]# chmod +x /etc/rc.d/init.d/mysqld
[[email protected] opt]# chkconfig  --add mysqld
[[email protected] opt]# chkconfig  --list mysqld
            mysqld          0:off   1:off   2:off   3:off   4:off   5:off   6:off

  执行service mysqld stop关闭命令

[[email protected] opt]# service mysqld stop
2018-11-23T04:14:04.201042Z mysqld_safe mysqld from pid file /var/run/mysqld/mysqld.pid ended
Stopping mysqld:                                           [  OK  ]
[1]+  Done                    /opt/mysql/bin/mysqld_safe --user=mysql
[[email protected] opt]# 

  然后在执行service mysqld start启动命令

[[email protected] opt]# service mysqld start
MySQL Daemon failed to start.
Starting mysqld:                                           [FAILED]

  启动失败,日志如下:

181123 12:59:03 mysqld_safe Starting mysqld daemon with databases from /opt/mysql/data
/usr/libexec/mysqld: Table ‘mysql.plugin‘ doesn‘t exist
181123 12:59:03 [ERROR] Can‘t open the mysql.plugin table. Please run mysql_upgrade to create it.
181123 12:59:03  InnoDB: Initializing buffer pool, size = 8.0M
181123 12:59:03  InnoDB: Completed initialization of buffer pool
InnoDB: Error: log file ./ib_logfile0 is of different size 0 50331648 bytes
InnoDB: than specified in the .cnf file 0 5242880 bytes!
181123 12:59:03 [ERROR] Plugin ‘InnoDB‘ init function returned error.
181123 12:59:03 [ERROR] Plugin ‘InnoDB‘ registration as a STORAGE ENGINE failed.
181123 12:59:03 [ERROR] Fatal error: Can‘t open and lock privilege tables: Table ‘mysql.host‘ doesn‘t exist
181123 12:59:03 mysqld_safe mysqld from pid file /var/run/mysqld/mysqld.pid ended

  一直不明白这个问题。

  执行以下命令解决问题:mysql_install_db --user=mysql --basedir=/usr/ --ldata=/opt/mysql/data/

[[email protected] bin]# mysql_install_db --user=mysql --basedir=/usr/ --ldata=/opt/mysql/data/Installing MySQL system tables...OKFilling help tables...OK To start mysqld at boot time you have to copysupport-files/mysql.server to the right place for your system PLEASE REMEMBER TO SET A PASSWORD FOR THE MySQL root USER !To do so, start the server, then issue the following commands: /usr//bin/mysqladmin -u root password ‘new-password‘/usr//bin/mysqladmin -u root -h centos04 password ‘new-password‘ Alternatively you can run:/usr//bin/mysql_secure_installation which will also give you the option of removing the testdatabases and anonymous user created by default.  This isstrongly recommended for production servers. See the manual for more instructions. You can start the MySQL daemon with:cd /usr/ ; /usr//bin/mysqld_safe & You can test the MySQL daemon with mysql-test-run.plcd /usr//mysql-test ; perl mysql-test-run.pl Please report any problems with the /usr//scripts/mysqlbug script! [[email protected] bin]#

  然后在执行service mysqld start启动命令

[[email protected] opt]# service mysqld start
Starting mysqld:                                           [  OK  ]
[[email protected] opt]# 

  查看启动进程,ps -ef | grep mysql 

[[email protected] opt]# ps -ef|grep mysql
root      8521  5731  0 11:40 pts/1    00:00:00 tail -f mysqld.log
root     15791     1  0 13:02 pts/0    00:00:00 /bin/sh /usr/bin/mysqld_safe --datadir=/opt/mysql/data                             --socket=/var/lib/mysql/mysql.sock --pid-file=/var/run/mysqld/mysqld.pid --basedir=/usr --user=mysql
mysql    15908 15791  0 13:02 pts/0    00:00:00 /usr/libexec/mysqld --basedir=/usr --datadir=/opt/mysql/data --user=mysql --log-error=/var/log/mysqld.log                             --pid-file=/var/run/mysqld/mysqld.pid --socket=/var/lib/mysql/mysql.sock
root     16020 21837  0 13:06 pts/0    00:00:00 grep mysql
[[email protected] opt]# 

  4.解决前面登录修改密码失败

    以root用户登录,mysql -u root

[[email protected] opt]# mysql -u root
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 5
Server version: 5.1.71 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> 

 修改root密码

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 Password=PASSWORD(‘Root#2018‘) where USER=‘root‘ and host=‘root‘ or host=‘localhost‘;
Query OK, 0 rows affected (0.00 sec)
Rows matched: 2  Changed: 0  Warnings: 0

mysql> 

  5.防火墙添加端口

    我这里是关闭了防火墙的。

  6.将user表的 host 改为 %,否则外网通过客户端工具会链接不上

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 Password=PASSWORD(‘Root#2018‘) where USER=‘root‘ and host=‘root‘ or host=‘localhost‘;
Query OK, 0 rows affected (0.00 sec)
Rows matched: 2  Changed: 0  Warnings: 0

mysql> use mysql
Database changed
mysql> update user set host =‘%‘where user =‘root‘ and host =‘localhost‘;
Query OK, 1 row affected (0.01 sec)
Rows matched: 1  Changed: 1  Warnings: 0

mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)

mysql> 

  

  加上过程问题处理,这次用时3个小时,时间太长了.......

原文地址:https://www.cnblogs.com/fameg/p/10015387.html

时间: 2024-10-13 09:04:56

MYSQL数据的安装、配置的相关文章

MySQL多实例安装配置

MySQL多实例安装配置 一.基本概念 MySQL多实例就是,在一台机器上开启多个不同的服务端口(如:3306,3307,3308...),运行多个MySQL服务进程,这些服务进程通过不同的socket监听不同的端口提供服务. MySQL可以共用一套安全程序,使用不同的my.cnf配置文件,启动程序,数据文件. 逻辑上是独立的,但是一个实例过载过高的时候会对其他造成影响. MySQL多实例的作用与问题: 1.有效利用服务器资源 2.节约服务器资源 3.资源互相抢占问题 当某个服务实现并发生很高的

MySQL压缩版安装配置教程

MySQL压缩版安装配置教程 1.下载 在官网下载压缩包(这里我下载的是第二个) 下载地址:https://dev.mysql.com/downloads/mysql/5.7.html#downloads 2.安装与配置 1.将压缩包解压到任意目录 2.如上图,在该目录下创建一个data空文件夹,再建一个my.ini的配置文件,在该文件中写入以下代码: 注意:以下代码的注释是必须删除的,也就是#号及其后面的中文必须都删掉,还有就是下面的basedir和datadir要改成自己相应的目录 [mys

Win10系统下MySQL压缩版安装配置教程

MySQL分为安装版和压缩.为了以后MySQL出问题想重装时的各种不必要的麻烦,我个人推荐压缩版MySQL.下面进入教程: 进入官网下载MySQL压缩包,并解压如下 配置环境变量---将bin文件的目录加入电脑系统环境配置path下 新建my.ini配置文件(安装目录和数据库存放目录根据自己的目录编辑) [mysql] default-character-set = utf8 [mysqld] #端口 port = 3306 #mysql安装目录 basedir = E:/mysql-8.0.1

MySQL系列 - MySQL源码安装配置

二.MySQL系列 - MySQL源码安装配置(附5.7等最新版本)1.依赖环境准备2.开始安装2.1.下载MySQL2.2.解压2.3.赋权限2.4.修改配置文件2.5.启动MySQL3.MySQL 5.7源码安装不同之处 二.MySQL系列 - MySQL源码安装配置(附5.7等最新版本) 1.依赖环境准备 make安装 make编译器下载地址:http://www.gnu.org/software/make/ # tar zxvf make-3.82.tar.gz # cd make-3.

mysql cluster (mysql 集群)安装配置方案(转)

一.准备 1.准备服务器 计划建立有5个节点的MySQL CLuster体系,需要用到5台服务器,但是我们做实验时没有这么多机器,可以只用2台,我就是一台本机,一台虚拟机搭建了有5个节点的MySQL CLuster体系,将一个SQL节点一个数据节点一个SQL节点放在了一台服务器上(192.168.1.252),将另一个SQL节点和一个数据节点放在了另外一台服务器上(192.168.1.52). 节点配置说明 节点 对应的IP和端口 管理节点(1个) 192.168.1.252 SQL节点 (2个

mysql cluster (mysql 集群)安装配置方案

一.说明 本文参考:http://www.cnblogs.com/jackluo/archive/2013/01/19/2868152.html 1.准备服务器 计划建立有5个节点的MySQL CLuster体系,需要用到5台服务器,但是我们做实验时没有这么多机器,可以只用3台,提供5个节点的MySQL CLuster体系,将SQL节点和数据节点共用一台机器,具体如下. 主机名 节点 对应的IP和端口 DB-mgm 管理节点 10.10.6.201:1186 DB-node1 数据节点 10.1

Linux下python3、virtualenv、Mysql、redis安装配置

一.在Linux安装python解释器 1.下载python3源码包 cd /opt/ wget https://www.python.org/ftp/python/3.6.2/Python-3.6.2.tgz 2.下载python3编译的依赖包(复制粘贴下载即可) yum install gcc patch libffi-devel python-devel zlib-devel bzip2-devel openssl-devel ncurses-devel sqlite-devel read

[原创]mysql 5.6安装配置,主从分离,读写分离简单教程

文章中参考使用了多个博客的资料,汇总而成!其流程准确性被人亦本人实践! https://blog.csdn.net/qq_35206261/article/details/81321201 https://www.cnblogs.com/qianniao12/p/8011222.html https://blog.csdn.net/qq_35206261/article/details/81321201 https://blog.csdn.net/why15732625998/article/d

ubuntu linux系统中安装mysql以及windows安装配置sqlyog

一.linux系统安装mysql Ubuntu上安装MySQL非常简单只需要几条命令就可以完成. 1. sudo apt-get install mysql-server 2. apt-get isntall mysql-client 3.  sudo apt-get install libmysqlclient-dev 安装过程中会提示设置密码什么的,注意设置了不要忘了,安装完成之后可以使用如下命令来检查是否安装成功: sudo netstat -tap | grep mysql 通过上述命令