当前位置:   article > 正文

实践:Linux下安装mysql8.0_mysql8 basedir

mysql8 basedir

目录

前言

一、下载mysql8.0安装包

1、在local创建mysql文件夹

2、使用wget下载mysql8.0的xz安装包

二、解压mysql8.0安装包

1、解压

2、重命名解压后的mysql文件夹(名字太长了)

3、创建data存储文件

三、创建用户和用户组,并赋予权限

1、创建用户和用户组

2、给用户赋予权限

四、初始化mysql信息

1、切换到mysql8.0安装路径下

2、初始化mysql基本信息

3、获取到临时mysql密码

 五、添加mysqld服务到系统

1、将mysqld服务添加到系统中

2、授权以及添加服务

3、mysql5.7以后就没有my.cnf了,所以我们创建一个。(个人觉得方便一些)

 4、启动mysql服务

如果出现下面报错

 解决

5、查看mysql服务状态

6、将mysql命令添加到服务  

六、登录mysql

1、登录 密码使用之前随机生成的密码

2、修改管理员密码  其中123456是新的密码自己设置 

3、重新加载缓存,使密码生效

4、退出mysql,用新密码尝试登录管理员

七、修改mysql配置,使其可以用工具远程登录

云服务器不能远程连接mysql,解决

 总结


前言

为教需要学习怎么使用Linux和安装mysql的朋友特此写的一篇文章。

同时也是为了记录自己的学习脚印。

本人在阿里云买了一台崭新的ESC服务器来写这篇文章

服务器操作系统:Alibaba Cloud Linux 3.2104 64位


一、下载mysql8.0安装包

1、在local创建mysql文件夹

cd /usr/local

mkdir mysql

cd mysql

2、使用wget下载mysql8.0的xz安装包

 wget https://dev.mysql.com/get/Downloads/MySQL-8.0/mysql-8.0.20-linux-glibc2.12-x86_64.tar.xz

二、解压mysql8.0安装包

1、解压

tar -xvf mysql-8.0.21-linux-glibc2.12-x86_64.tar.xz

2、重命名解压后的mysql文件夹(名字太长了)

mv mysql-8.0.21-linux-glibc2.12-x86_64 mysql8.0

3、创建data存储文件

cd mysql8.0

mkdir data

三、创建用户和用户组,并赋予权限

1、创建用户和用户组

groupadd mysql
 
useradd -g mysql mysql

2、给用户赋予权限

chown -R mysql.mysql /usr/local/mysql/mysql8.0

四、初始化mysql信息

1、切换到mysql8.0安装路径下

Tip:绝对路径:cd /usr/local/mysql/mysql8.0/bin

cd bin

2、初始化mysql基本信息

./mysqld --user=mysql --basedir=/usr/local/mysql/mysql8.0 --datadir=/usr/local/mysql/mysql8.0/data/ --initialize

3、获取到临时mysql密码

 五、添加mysqld服务到系统

1、将mysqld服务添加到系统中

cd /usr/local/mysql/mysql8.0

cp -a ./support-files/mysql.server /etc/init.d/mysql

2、授权以及添加服务

chmod +x /etc/init.d/mysql

chkconfig --add mysql

3、mysql5.7以后就没有my.cnf了,所以我们创建一个。(个人觉得方便一些)

cd /etc

sudo vim my.cnf

  1. # Example MySQL config file for small systems.
  2. #
  3. # This is for a system with little memory (<= 64M) where MySQL is only used
  4. # from time to time and it's important that the mysqld daemon
  5. # doesn't use much resources.
  6. #
  7. # MySQL programs look for option files in a set of
  8. # locations which depend on the deployment platform.
  9. # You can copy this option file to one of those
  10. # locations. For information about these locations, see:
  11. # http://dev.mysql.com/doc/mysql/en/option-files.html
  12. #
  13. # In this file, you can use all long options that a program supports.
  14. # If you want to know which options a program supports, run the program
  15. # with the "--help" option.
  16. # The following options will be passed to all MySQL clients
  17. [client]
  18. default-character-set=utf8
  19. #password = k0Ui&wV(Z3yt
  20. port = 3306
  21. socket = /tmp/mysql.sock
  22. # Here follows entries for some specific programs
  23. # The MySQL server
  24. [mysqld]
  25. #配置mysql的文件夹 和 mysql data目录
  26. basedir=/usr/local/mysql/mysql8.0
  27. datadir=/usr/local/mysql/mysql8.0/data
  28. default-storage-engine=INNODB
  29. character-set-server=utf8
  30. collation-server=utf8_general_ci
  31. port = 3306
  32. socket = /tmp/mysql.sock
  33. skip-external-locking
  34. key_buffer_size = 16K
  35. max_allowed_packet = 1M
  36. table_open_cache = 4
  37. sort_buffer_size = 64K
  38. read_buffer_size = 256K
  39. read_rnd_buffer_size = 256K
  40. net_buffer_length = 2K
  41. thread_stack = 128K
  42. # Don't listen on a TCP/IP port at all. This can be a security enhancement,
  43. # if all processes that need to connect to mysqld run on the same host.
  44. # All interaction with mysqld must be made via Unix sockets or named pipes.
  45. # Note that using this option without enabling named pipes on Windows
  46. # (using the "enable-named-pipe" option) will render mysqld useless!
  47. #
  48. #skip-networking
  49. server-id = 1
  50. # Uncomment the following if you want to log updates
  51. #log-bin=mysql-bin
  52. # binary logging format - mixed recommended
  53. #binlog_format=mixed
  54. # Causes updates to non-transactional engines using statement format to be
  55. # written directly to binary log. Before using this option make sure that
  56. # there are no dependencies between transactional and non-transactional
  57. # tables such as in the statement INSERT INTO t_myisam SELECT * FROM
  58. # t_innodb; otherwise, slaves may diverge from the master.
  59. #binlog_direct_non_transactional_updates=TRUE
  60. # Uncomment the following if you are using InnoDB tables
  61. #innodb_data_home_dir = /usr/local/mysql/data
  62. #innodb_data_file_path = ibdata1:10M:autoextend
  63. #innodb_log_group_home_dir = /usr/local/mysql/data
  64. # You can set .._buffer_pool_size up to 50 - 80 %
  65. # of RAM but beware of setting memory usage too high
  66. #innodb_buffer_pool_size = 16M
  67. #innodb_additional_mem_pool_size = 2M
  68. # Set .._log_file_size to 25 % of buffer pool size
  69. #innodb_log_file_size = 5M
  70. #innodb_log_buffer_size = 8M
  71. #innodb_flush_log_at_trx_commit = 1
  72. #innodb_lock_wait_timeout = 50
  73. [mysqldump]
  74. quick
  75. max_allowed_packet = 16M
  76. [mysql]
  77. no-auto-rehash
  78. # Remove the next comment character if you are not familiar with SQL
  79. #safe-updates
  80. [myisamchk]
  81. key_buffer_size = 8M
  82. sort_buffer_size = 8M
  83. [mysqlhotcopy]
  84. interactive-timeout

*设置my.cnf权限

sudo chmod 664 /etc/my.cnf

 4、启动mysql服务(启动服务注意my.cnf文件中配置的3306端口是否被占用)

service mysql start

如果出现下面报错(1)

 解决

将/var/lock/subsys/下mysql文件删除

如果出现下面报错(2)

 先cat去查看这个err文件,端口占用解决方法

lsof -i tcp:3306

kill 26788

5、查看mysql服务状态

service mysql status

6、将mysql命令添加到服务  

ln -s /usr/local/mysql/mysql8.0/bin/mysql /usr/bin

六、登录mysql

1、登录 密码使用之前随机生成的密码

mysql  mysql -uroot -p

如果出现以下错误:

 mysql: error while loading shared libraries: libtinfo.so.5: cannot open shared object file: No such file or directory

 

执行:

  1. ## 软连接出一个新的文件
  2. sudo ln -s /usr/lib64/libtinfo.so.6.1 /usr/lib64/libtinfo.so.5
  3. ## 执行完上条指令后,重新进行登录即可
  4. ./mysql -u root -p

2、修改管理员密码  其中123456是新的密码自己设置 

ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY '123456';

3、重新加载缓存,使密码生效

flush privileges;

4、退出mysql,用新密码尝试登录管理员

七、修改mysql配置,使其可以用工具远程登录

mysql -uroot -p123456

use mysql

update user set host='%' where user='root';

// 赋予root全部权限

GRANT ALL PRIVILEGES ON *.* TO 'root'@'%'

 如果报错

 重新执行:

update user set host='%' where user='root';

再:

GRANT ALL PRIVILEGES ON *.* TO 'root'@'%';

为什么第二遍可以,应该是跟mysql缓存有关。

最后:

flush privileges;

云服务器不能远程连接mysql,解决

如果是买的云服务器,例如:阿里云服务器的,请到设置mysql(3306)安全策略


 总结

到此就已经完成了在Linux中mysql8.0的所有安装。希望对大家有所帮助。

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

闽ICP备14008679号