您现在的位置是:首页 > 博客日记 > 数据库 数据库

liunx mysql8.0安装教程

2019-11-13 10:19:12 【数据库】 人已围观

安装目录

安装文件下载目录:/data/software
Mysql目录安装位置:/usr/local/mysql
数据库保存位置:/data/mysql
日志保存位置:/data/log/mysql

下载mysql

在官网:http://dev.mysql.com/downloads/mysql/ 中,选择以下版本的mysql下载:

执行如下命名:

  1. mkdir /data/software
  2. cd /data/software

1.下载安装包

建议:在windows上使用迅雷下载,速度很快(我的是1M/s),然后用工具(Xftp)上传到 /data/software目录下;

  1. wget https://cdn.mysql.com//Downloads/MySQL-8.0/mysql-8.0.18-linux-glibc2.12-i686.tar.xz

2.解压压缩包

  1. tar xvJf mysql-8.0.18-linux-glibc2.12-i686.tar.xz
  1. 移动并修改文件名
    1. mv /data/software/mysql-8.0.18-linux-glibc2.12-i686 /usr/local/mysql

4.创建数据仓库目录 /data/mysql 数据仓库目录

  1. mkdir /data/mysql

5新建mysql用户、组及目录

  1. #新建一个msyql组
  2. groupadd mysql
  3. #新建msyql用户禁止登录shell
  4. useradd -r -s /sbin/nologin -g mysql mysql -d /usr/local/mysql

6改变目录属有者

  1. cd /usr/local/
  2. chown -R mysql mysql
  3. chgrp -R mysql mysql
  4. chown -R mysql /data/mysql

7初始化mysql 并配置参数

  1. [root@dxt232 bin]# /usr/local/mysql/bin/mysqld --initialize --user=mysql --basedir=/usr/local/mysql --datadir=/data/mysql
  2. 2019-11-18T07:19:52.401741Z 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.
  3. 2019-11-18T07:19:52.401958Z 0 [System] [MY-013169] [Server] /usr/local/webserver/mysql/bin/mysqld (mysqld 8.0.18) initializing of server in progress as process 17479
  4. 2019-11-18T07:19:59.020850Z 5 [Note] [MY-010454] [Server] A temporary password is generated for root@localhost: eu#y#aaKZ0V7

此处需要注意记录生成的临时密码,如上文结尾处的:eu#y#aaKZ0V7

  1. /usr/local/mysql/bin/mysql_ssl_rsa_setup --datadir=/data/mysql

如果报错

  1. [root@dxt232 mysql]# /usr/local/webserver/mysql/bin/mysqld --initialize --user=mysql --basedir=/usr/local/webserver/mysql --datadir=/data/mysql-bash: /usr/local/webserver/mysql/bin/mysqld: /lib/ld-linux.so.2: bad ELF interpreter: No such file or directory

解决报错出现的缺少软件扩展

  1. yum install -y glibc.i686 libstdc++.so.6 libaio.i686 numactl-libs.i686

8.修改系统配置文件

  1. cd /usr/local/mysql/support-files
  2. cp mysql.server /etc/init.d/mysql
  1. vim /etc/init.d/mysql

修改以下内容:

  1. vim /etc/my.conf

修改以下内容:

9启动mysql
创建 /data/logs/mysql.log 日志文件, 并赋权chown mysql.mysql /data/logs/mysql.log

  1. service mysql start

—登陆

  1. # mysql -hlocalhost -uroot -p

—如果出现:-bash: mysql: command not found
—就执行: # ln -s /usr/local/mysql/bin/mysql /usr/bin —没有出现就不用执行

如果报错

  1. [root@dxt232 mysql]# /usr/local/webserver/mysql/bin/mysql -uroot -p
  2. Enter password:
  3. ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2)
  4. [root@dxt232 mysql]# ln -s /data/mysql/mysql.sock /tmp/mysql.sock

—输入第6步生成的临时密码

—修改密码

  1. mysql> ALTER USER USER() IDENTIFIED BY 'root';

—设置root账户的host地址(修改了才可以远程连接)

  1. mysql>grant all privileges on *.* to 'root'@'%' identified by 'root';
  2. mysql>flush privileges;

—查看表

  1. mysql> use mysql;
  2. mysql> select host,user from user;

—这里就可以使用远程连接测试了;

如提示不能成功连接,可能需要添加需要监听的端口

  1. /sbin/iptables -I INPUT -p tcp --dport 3306 -j ACCEPT

10添加系统路径

  1. # vim /etc/profile

添加:

  1. export PATH=/usr/local/mysql/bin:$PATH

如下:

  1. # source /etc/profile

11配置mysql自动启动

  1. # chmod 755 /etc/init.d/mysql
  2. # chkconfig --add mysql
  3. # chkconfig --level 345 mysql on

以上就是linux环境Mysql 5.7.13安装教程,希望对大家的学习有所帮助。

补充:

—退出mysql命令窗口

  1. #exit

—查看mysql状态

  1. #service mysql status

—停止mysql

  1. #service mysql stop

—启动mysql

  1. #service mysql start

附my.cnf(这是一个配置mysql配置文件,暂时可以不用管,如你想钻研 你可以百度或google “mysql my.cnf 配置详情”)

/etc/my.cnf

  1. # For advice on how to change settings please see
  2. # http://dev.mysql.com/doc/refman/5.7/en/server-configuration-defaults.html
  3. # *** DO NOT EDIT THIS FILE. It's a template which will be copied to the
  4. # *** default location during install, and will be replaced if you
  5. # *** upgrade to a newer version of MySQL.
  6. [mysqld]
  7. # Remove leading # and set to the amount of RAM for the most important data
  8. # cache in MySQL. Start at 70% of total RAM for dedicated server, else 10%.
  9. innodb_buffer_pool_size = 10G
  10. # Remove leading # to turn on a very important data integrity option: logging
  11. # changes to the binary log between backups.
  12. log_bin
  13. character-set-server=utf8
  14. collation-server=utf8_bin
  15. init-connect='SET NAMES utf8'
  16. # These are commonly set, remove the # and set as required.
  17. basedir = /usr/local/mysql
  18. datadir = /export/mysql/var
  19. port = 3306
  20. server_id = 22206
  21. socket = /export/mysql/mysql.sock
  22. binlog_format = statement
  23. # Remove leading # to set options mainly useful for reporting servers.
  24. # The server defaults are faster for transactions and fast SELECTs.
  25. # Adjust sizes as needed, experiment to find the optimal values.
  26. join_buffer_size = 128M
  27. sort_buffer_size = 2M
  28. read_rnd_buffer_size = 2M
  29. log_bin_trust_function_creators = on
  30. sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES
  31. lower_case_table_names=1


关注TinyMeng博客,更多精彩分享,敬请期待!
 

很赞哦! ()