当前位置:   article > 正文

MYSQL 8.X Linux-Generic 通用版本安装_linux-generic mysql安装

linux-generic mysql安装

下载对应版本MySQL :: Download MySQL Community Server (Archived Versions)

这里我选择的是Linux - Generic (glibc 2.12) (x86, 64-bit), TAR

解压到服务器 只需要里面的mysql-8.0.24-linux-glibc2.12-x86_64.tar.xz

文末有新版本安装的持续更新

在目录下创建需要的文件夹

这里我改名为mysql-8.0.24

  1. cd /mysql-8.0.24
  2. mkdir data
  3. mkdir temp
  4. mkdir log
  5. cd /mysql-8.0.24/log
  6. touch error.log
  7. chown -R mysql:mysql /mysql-8.0.24
  8. chmod -R 750 /mysql-8.0.24
  9. cd /mysql-8.0.24
  10. ./bin/mysqld --initialize --console --user=mysql --basedir=/mysql-8.0.24 --datadir=/mysql-8.0.24/data

在log/error.log中找到默认密码

启动服务

  1. su mysql
  2. /mysql-8.0.24/bin/mysqld --defaults-file=/mysql-8.0.24/my.cnf &

使用密码登录

  1. cd /mysql-8.0.24
  2. ./bin/mysql -uroot -h 127.0.0.1 -p
  3. alter user 'root'@'localhost' identified by 'xxxx';
  4. #设置远程登录
  5. create user root@'%' identified by 'xxxx';
  6. grant all privileges on *.* to root@'%' with grant option;
  7. flush privileges;

补上使用的配置文件 里面的路径需要更换成实际使用的目录

  1. [mysql]
  2. #设置mysql客户端默认字符集
  3. default-character-set=utf8
  4. [mysqld]
  5. sql_mode=NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO
  6. user=mysql
  7. skip-name-resolve
  8. #设置3306端口
  9. port = 3306
  10. #缓存配置
  11. tmp_table_size=1024M
  12. max_heap_table_size=1024M
  13. #设置mysql的安装目录
  14. basedir=/mysql-8.0.24
  15. #设置mysql数据库的数据的存放目录 错误日志
  16. datadir=/mysql-8.0.24
  17. tmpdir=/mysql-8.0.24/temp
  18. pid-file=/mysql-8.0.24/mysql.pid
  19. log-error=/mysql-8.0.24/log/error.log
  20. pid-file=/mysql-8.0.24/mysql.pid
  21. #允许最大连接数
  22. max_connections=200
  23. #服务端使用的字符集默认为8比特编码的latin1字符集
  24. character-set-server=utf8
  25. init_connect='SET NAMES utf8'
  26. default_authentication_plugin=mysql_native_password
  27. #创建新表时将使用的默认存储引擎
  28. default-storage-engine=INNODB
  29. #此处是区分大写的,但是mysql8只有在初始化时设置lower_case_table_names=1才有效
  30. #lower_case_table_names=1
  31. max_allowed_packet=500M
  32. #取消binlog
  33. skip-log-bin
  34. #开启load file
  35. local-infile=1
  36. secure_file_priv=

ps 最新更新 8.0.36安装

新版初始化语句需要调整

  1. cd /mysql-8.0.36
  2. ./bin/mysqld --initialize --console --user=mysql --basedir=/your path/mysql-8.0.36 --datadir=/data

若出现 [ERROR] [MY-010338] [Server] Can't find error-message file '/mysql-8.0.36/share/errmsg.sys'. Check error-message file location and 'lc-messages-dir' configuration directive.

则需要把文件放在指定目录

2024-04-03:新版本(8.2.0)的初始化需要指定error的路径 

./bin/mysqld --initialize --console --user=mysql --basedir=/mysql-8.0.24 --datadir=/mysql-8.0.24/data --log-error=/mysql-8.0.24/log/error.log

2024-05-22:新版本(8.4.0)初始化需要拷贝一份可以使用的my.cnf到 /etc目录,并且设置[mysqld]
user=root

这里可以直接使用上面的,该文件只作为初始化处理使用,,不然会一直报错he designated data directory /xxx/data/ is unusable. 或者该data文件无权限

初始化完毕后需要重新赋予权限给data目录下的文件,新版初始化后权限不对

  1. chown -R mysql:mysql /mysql-8.4.0
  2. chmod -R 750 /mysql-8.4.0

这里没赋权时日志内报错

[ERROR] [MY-012273] [InnoDB] Can't create file './ibdata1' when --innodb-read-only is set

[Warning] [MY-012197] [InnoDB] Unable to open './data/mysql.ibd'

最后一个大坑就是data目录

上文中提到的示例my.cnf在之前的版本都是可以正常使用的,新版4.0需要将data目录写完整

  1. [mysqld]
  2. basedir=/mysql-8.4.0
  3. #这里需要注意,需要完整路径
  4. datadir=/mysql-8.4.0/data
  5. tmpdir=/mysql-8.4.0/temp
  6. pid-file=/mysql-8.4.0/mysql.pid
  7. log-error=/mysql-8.4.0/log/error.log
  8. pid-file=/mysql-8.4.0/mysql.pid

报错信息

  1. [ERROR] [MY-012592] [InnoDB] Operating system error number 2 in a file operation.
  2. [ERROR] [MY-012593] [InnoDB] The error means the system cannot find the path specified.
  3. [ERROR] [MY-012594] [InnoDB] If you are installing InnoDB, remember that you must create directories yourself, InnoDB does not create them.
  4. [ERROR] [MY-012646] [InnoDB] File ./ibdata1: 'open' returned OS error 71. Cannot continue operation
  5. [ERROR] [MY-012981] [InnoDB] Cannot continue operation.

命令登录时不再需要-h指定127.0.0.1来登录了,会报错无法登录去掉就可以了

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/Li_阴宅/article/detail/981910
推荐阅读
相关标签
  

闽ICP备14008679号