侯体宗的博客
  • 首页
  • Hyperf版
  • beego仿版
  • 人生(杂谈)
  • 技术
  • 关于我
  • 更多分类
    • 文件下载
    • 文字修仙
    • 中国象棋ai
    • 群聊
    • 九宫格抽奖
    • 拼图
    • 消消乐
    • 相册

Linux下安装配置MySQL

linux  /  管理员 发布于 7年前   247

系统:Ubuntu 16.04LTS

1\官网下载mysql-5.7.18-linux-glibc2.5-x86_64.tar.gz

2\建立工作组:

$su#groupadd mysql#useradd -r -g mysql mysql

3\创建目录

#mkdir /usr/local/mysql#mkdir /usr/local/mysql/data

4\解压mysql-5.7.18-linux-glibc2.5-x86_64.tar.gz,并拷贝至/usr/local/mysql

#tar -zxvf mysql-5.7.18-linux-glibc2.5-x86_64.tar.gz#cp -r /home/jieyamulu/mysql-5.7.18-linux-glibc2.5-x86_64/* /usr/local/mysql

5\修改mysql用户对mysql以下及其子文件夹以下文件的权限,修改后可使用ll查看权限

root@Ice-***:/usr/local# chown -R mysql:mysql mysqlroot@Ice-***:/usr/local# ll总用量 44drwxr-xr-x 11 root root 4096 5月 19 07:39 ./drwxr-xr-x 11 root root 4096 2月 16 04:30 ../drwxr-xr-x 2 root root 4096 2月 16 04:19 bin/drwxr-xr-x 2 root root 4096 2月 16 04:19 etc/drwxr-xr-x 2 root root 4096 2月 16 04:19 games/drwxr-xr-x 2 root root 4096 2月 16 04:19 include/drwxr-xr-x 4 root root 4096 2月 16 04:23 lib/lrwxrwxrwx 1 root root   9 3月 29 14:11 man -> share/man/drwxr-xr-x 10 mysql mysql 4096 5月 19 07:48 mysql/drwxr-xr-x 2 root root 4096 2月 16 04:19 sbin/drwxr-xr-x 8 root root 4096 2月 16 04:34 share/drwxr-xr-x 2 root root 4096 2月 16 04:19 src/root@Ice-***:/usr/local# cd mysql/root@Ice-***:/usr/local/mysql# ll总用量 64drwxr-xr-x 10 mysql mysql 4096 5月 19 07:48 ./drwxr-xr-x 11 root root  4096 5月 19 07:39 ../drwxr-xr-x 2 mysql mysql 4096 5月 19 07:48 bin/-rw-r--r-- 1 mysql mysql 17987 5月 19 07:48 COPYINGdrwxr-xr-x 2 mysql mysql 4096 5月 19 07:41 data/drwxr-xr-x 2 mysql mysql 4096 5月 19 07:48 docs/drwxr-xr-x 3 mysql mysql 4096 5月 19 07:48 include/drwxr-xr-x 5 mysql mysql 4096 5月 19 07:48 lib/drwxr-xr-x 4 mysql mysql 4096 5月 19 07:48 man/-rw-r--r-- 1 mysql mysql 2478 5月 19 07:48 READMEdrwxr-xr-x 28 mysql mysql 4096 5月 19 07:48 share/drwxr-xr-x 2 mysql mysql 4096 5月 19 07:48 support-files/

6\修改(或新建)/etc/my.cnf 配置文件

root@Ice-***:/usr/local/mysql# vim /etc/my.cnf [mysqld] basedir=/usr/local/mysql/datadir=/usr/local/mysql/data:wq

7\最关键的初始化

# cd /usr/local/mysql/root@Ice-***:/usr/local/mysql# ./bin/mysqld --user=mysql --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data --initialize2017-05-19T00:15:46.529420Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).2017-05-19T00:15:47.066125Z 0 [Warning] InnoDB: New log files created, LSN=457902017-05-19T00:15:47.213711Z 0 [Warning] InnoDB: Creating foreign key constraint system tables.2017-05-19T00:15:47.286951Z 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: 4e958344-3c28-11e7-8334-c8d3ffd2db82.2017-05-19T00:15:47.292857Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened.2017-05-19T00:15:47.294758Z 1 [Note] A temporary password is generated for root@localhost: YjaotQk*2ew4

初始密码要记住
这里可能会出现很多问题,比如:

Installing MySQL system tables..../bin/mysqld: error while loading shared libraries: libaio.so.1: cannot open shared object file: No such file or directory

缺少依赖关系包

解决方法:sudo apt-get install libaio-dev

还有可能是之前步骤不对导致了操作data文件的权限不够等等.按照步骤来,缺少什么装什么(有提示),到了这里应该就初始化成功了,那几个Warning,值得注意的是Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened.有时间可以查下是怎么回事,这条忽略也没影响.

8\不要着急启动,现在还启动不了.执行代码,将mysql下除了data文件夹外的文件变为root权限

root@Ice-***:/usr/local/mysql# chown -R root .root@Ice-***:/usr/local/mysql# chown -R mysql data

9\启动

root@Ice-***:/usr/local/mysql# bin/mysqld_safe --user=mysql &

敲回车

root@Ice-***:/usr/local/mysql# /usr/local/mysql/bin/mysql -uroot -pEnter password: Welcome to the MySQL monitor. Commands end with ; or \g.Your MySQL connection id is 3Server version: 5.7.18Copyright (c) 2000, 2017, Oracle and/or its affiliates. All rights reserved.Oracle is a registered trademark of Oracle Corporation and/or itsaffiliates. Other names may be trademarks of their respectiveowners.Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.mysql> show databases;ERROR 1820 (HY000): You must reset your password using ALTER USER statement before executing this statement.mysql> 

10\重置密码

mysql> SET PASSWORD = PASSWORD('newpasswd');Query OK, 0 rows affected, 1 warning (0.00 sec)mysql> show databases;+--------------------+| Database      |+--------------------+| information_schema || mysql       || performance_schema || sys        |+--------------------+4 rows in set (0.00 sec)mysql> quitBye

11\设置开机启动

root@Ice-***:/usr/local/mysql# cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqldroot@Ice-***:/usr/local/mysql# chmod 755 /etc/init.d/mysqld

12\安装mysql-server 和 mysql-client

root@Ice-***:~# apt-get install mysql-serverroot@Ice-***:~# apt-get install mysql-clientroot@Ice-***:~# apt-get install libmysqlclient-devE: Sub-process /usr/bin/dpkg returned an error code (1)

解决办法:

1.$ sudo mv /var/lib/dpkg/info /var/lib/dpkg/info_old //现将info文件夹更名 
2.$ sudo mkdir /var/lib/dpkg/info //再新建一个新的info文件夹 
3.$ sudo apt-get update,  
   $ apt-get -f install //修复依赖树
4.$ sudo mv /var/lib/dpkg/info/* /var/lib/dpkg/info_old //执行完上一步操作后会在新的info文件夹下生成一些文件,现将这些文件全部移到info_old文件夹下 
5.$ sudo rm -rf /var/lib/dpkg/info //把自己新建的info文件夹删掉 
6.$ sudo mv /var/lib/dpkg/info_old /var/lib/dpkg/info //把以前的info文件夹重新改回名字

最后,如果是Ubuntu系统可能无法向表中插入汉字,无法从表中查询汉字..

解决办法:

关闭数据库服务

service mysql stop~$ sudo vim /etc/mysql/mysql.conf.d/mysqld.cnf

在[mysqld]下添加一行character_set_server=utf8
配置文件选段:

[mysqld]## * Basic Settings#user      = mysqlpid-file    = /var/run/mysqld/mysqld.pidsocket     = /var/run/mysqld/mysqld.sockport      = 3306basedir     = /usrdatadir     = /var/lib/mysqltmpdir     = /tmplc-messages-dir = /usr/share/mysqlcharacter_set_server=utf8 就是这一行,原来是没有的,要手动添加!skip-external-locking#


将上述文件拷贝至/etc/mysql/my.cnf

~$ sudo cp /etc/mysql/mysql.conf.d/mysqld.cnf /etc/mysql/my.cnf

重启数据库服务

~$ /etc/init.d/mysql restart

如果查看字符集能得到如下结果就说明成功了.

mysql> show variables like 'collation_%';+----------------------+-----------------+| Variable_name    | Value      |+----------------------+-----------------+| collation_connection | utf8_general_ci || collation_database  | utf8_general_ci || collation_server   | utf8_general_ci |+----------------------+-----------------+3 rows in set (0.00 sec)mysql> show variables like 'character_set_%';+--------------------------+----------------------------+| Variable_name      | Value           |+--------------------------+----------------------------+| character_set_client   | utf8|| character_set_connection | utf8|| character_set_database  | utf8|| character_set_filesystem | binary           || character_set_results  | utf8|| character_set_server   | utf8|| character_set_system   | utf8|| character_sets_dir    | /usr/share/mysql/charsets/ |+--------------------------+----------------------------+8 rows in set (0.01 sec)


  • 上一条:
    Linux下MySQL5.7.18 yum方式从卸载到安装过程图解
    下一条:
    Mysql5.7在Centos6中的安装方法
  • 昵称:

    邮箱:

    0条评论 (评论内容有缓存机制,请悉知!)
    最新最热
    • 分类目录
    • 人生(杂谈)
    • 技术
    • linux
    • Java
    • php
    • 框架(架构)
    • 前端
    • ThinkPHP
    • 数据库
    • 微信(小程序)
    • Laravel
    • Redis
    • Docker
    • Go
    • swoole
    • Windows
    • Python
    • 苹果(mac/ios)
    • 相关文章
    • 在Linux系统中使用Iptables实现流量转发功能流程步骤(0个评论)
    • vim学习笔记-入门级需要了解的一些快捷键(0个评论)
    • 在centos7系统中实现分区并格式化挂载一块硬盘到/data目录流程步骤(0个评论)
    • 在Linux系统种查看某一个进程所占用的内存命令(0个评论)
    • Linux中grep命令中的10种高级用法浅析(0个评论)
    • 近期文章
    • 在go语言中使用api.geonames.org接口实现根据国际邮政编码获取地址信息功能(1个评论)
    • 在go语言中使用github.com/signintech/gopdf实现生成pdf分页文件功能(0个评论)
    • gmail发邮件报错:534 5.7.9 Application-specific password required...解决方案(0个评论)
    • 欧盟关于强迫劳动的规定的官方举报渠道及官方举报网站(0个评论)
    • 在go语言中使用github.com/signintech/gopdf实现生成pdf文件功能(0个评论)
    • Laravel从Accel获得5700万美元A轮融资(0个评论)
    • 在go + gin中gorm实现指定搜索/区间搜索分页列表功能接口实例(0个评论)
    • 在go语言中实现IP/CIDR的ip和netmask互转及IP段形式互转及ip是否存在IP/CIDR(0个评论)
    • PHP 8.4 Alpha 1现已发布!(0个评论)
    • Laravel 11.15版本发布 - Eloquent Builder中添加的泛型(0个评论)
    • 近期评论
    • 122 在

      学历:一种延缓就业设计,生活需求下的权衡之选中评论 工作几年后,报名考研了,到现在还没认真学习备考,迷茫中。作为一名北漂互联网打工人..
    • 123 在

      Clash for Windows作者删库跑路了,github已404中评论 按理说只要你在国内,所有的流量进出都在监控范围内,不管你怎么隐藏也没用,想搞你分..
    • 原梓番博客 在

      在Laravel框架中使用模型Model分表最简单的方法中评论 好久好久都没看友情链接申请了,今天刚看,已经添加。..
    • 博主 在

      佛跳墙vpn软件不会用?上不了网?佛跳墙vpn常见问题以及解决办法中评论 @1111老铁这个不行了,可以看看近期评论的其他文章..
    • 1111 在

      佛跳墙vpn软件不会用?上不了网?佛跳墙vpn常见问题以及解决办法中评论 网站不能打开,博主百忙中能否发个APP下载链接,佛跳墙或极光..
    • 2016-11
    • 2017-07
    • 2017-10
    • 2017-11
    • 2018-01
    • 2018-02
    • 2020-03
    • 2020-04
    • 2020-05
    • 2020-06
    • 2021-02
    • 2021-03
    • 2021-04
    • 2021-06
    • 2021-07
    • 2021-08
    • 2021-09
    • 2021-10
    • 2021-11
    • 2021-12
    • 2022-01
    • 2022-03
    • 2022-04
    • 2022-08
    • 2022-11
    • 2022-12
    • 2023-01
    • 2023-02
    • 2023-03
    • 2023-06
    • 2023-07
    • 2023-10
    • 2023-12
    • 2024-01
    • 2024-04
    Top

    Copyright·© 2019 侯体宗版权所有· 粤ICP备20027696号 PHP交流群

    侯体宗的博客