这篇文章主要为大家展示了“linux如何安装mysql5.7的方法”,内容简而易懂,条理清晰,希望能够帮助大家解决疑惑,下面让小编带领大家一起研究并学习一下“linux如何安装mysql5.7的方法”这篇文章吧。
mysql 单节点安装,前查询:https://my.oschina.net/u/3411575/blog/5047890
步骤1:
自行下载mysql5.7
步骤2:
解压:
tar -xvf mysql-5.7.26-linux-glibc2.12-x86_64.tar.gz
步骤3:
移动解压得到的文件夹,并重命名:
mv mysql-5.7.26-linux-glibc2.12-x86_64 /usr/local/mysql
步骤4:
创建文件夹
/home/mysql/data3306
/home/mysql/data3307
/home/mysql/data3309
步骤5:
编辑/etc/my.cnf
client] port=3306 socket=/tmp/mysql.sock [mysqld_multi] mysqld = /usr/local/mysql/bin/mysqld_safe mysqladmin = /usr/local/mysql/bin/mysqladmin log = /home/mysql/mysqld_multi.log [mysqld] user=mysql basedir = /usr/local/mysql sql_mode = STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION [mysqld3306] mysqld=mysqld mysqladmin=mysqladmin datadir=/home/mysql/data3306/data port=3306 server_id=3306 socket=/tmp/data3306.sock log-output=file slow_query_log = 1 long_query_time = 1 slow_query_log_file = /home/mysql/mysql3306/log/slow.log log-error = /home/mysql/mysql3306/log/error.log binlog_format = mixed log-bin = /home/mysql/mysql3306/log/mysql3306_bin [mysqld3309] mysqld=mysqld mysqladmin=mysqladmin datadir=/home/mysql/data3308/data port=3309 server_id=3309 socket=/tmp/data3309.sock log-output=file slow_query_log = 1 long_query_time = 1 slow_query_log_file = /home/mysql/mysql3309/log/slow.log log-error = /home/mysql/mysql3309/log/error.log binlog_format = mixed log-bin = /home/mysql/mysql3309/log/mysql3309_bin
步骤6:
新建单独实例的初始化配置文件(要与/etc/my.cnf文件配置保持一致) 分别存放在 /home/mysql/data3306 /home/mysql/data3307 /home/mysql/data3309 中
my.cnf(3306.cnf)
[client] port= 3306 socket= /home/mysql/data3306/mysql.sock default-character-set=utf8 [mysqld] user=mysql port=3306 basedir=/usr/local/mysql datadir=/home/mysql/data3306/data server_id=3306 socket=/home/mysql/data3306/mysql.sock log-output=file slow_query_log=1 long_query_time=1 slow_query_log_file=/home/mysql/data3306/log/slow.log symbolic-links=0 log-error=/home/mysql/data3306/log/error.log log-bin=/home/mysql/data3306/log/bin.log pid-file=/home/mysql/data3306/mysql3306.pid binlog_format=mixed lower-case-table_names=1 log-bin-trust-function-creators=1 sql_mode = STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION character-set-server=utf8
my.cnf(3307.cnf)
[client] port= 3307 socket= /home/mysql/data3307/mysql.sock default-character-set=utf8 [mysqld] user=mysql port=3307 basedir=/usr/local/mysql datadir=/home/mysql/data3307/data server_id=3307 socket=/home/mysql/data3307/mysql.sock log-output=file slow_query_log=1 long_query_time=1 slow_query_log_file=/home/mysql/data3307/log/slow.log symbolic-links=0 log-error=/home/mysql/data3307/log/error.log log-bin=/home/mysql/data3307/log/bin.log pid-file=/home/mysql/data3307/mysql3307.pid binlog_format=mixed lower-case-table_names=1 log-bin-trust-function-creators=1 sql_mode = STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION character-set-server=utf8
my.cnf(3309.cnf)
[client] port= 3309 socket= /home/mysql/data3309/mysql.sock default-character-set=utf8 [mysqld] user=mysql port=3309 basedir=/usr/local/mysql datadir=/home/mysql/data3309/data server_id=3309 socket=/home/mysql/data3309/mysql.sock log-output=file slow_query_log=1 long_query_time=1 slow_query_log_file=/home/mysql/data3309/log/slow.log symbolic-links=0 log-error=/home/mysql/data3309/log/error.log log-bin=/home/mysql/data3309/log/bin.log pid-file=/home/mysql/data3309/mysql3309.pid binlog_format=mixed lower-case-table_names=1 log-bin-trust-function-creators=1 sql_mode = STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION character-set-server=utf8
步骤6-1:
创建文件夹/home/mysql/data330{6,7,9}/log并创建文件图中4个文件
步骤7:
开始赋权限
chown mysql:mysql -R /home/mysql/ chown mysql:mysql -R /usr/local/mysql
步骤8:
初始化数据库, 这里生成mysql.sock文件 :
/usr/local/mysql/bin/mysqld --defaults-file=/home/mysql/data3306/my.cnf --initialize --basedir=/usr/local/mysql/ --datadir=/home/mysql/data3306/data /usr/local/mysql/bin/mysqld_safe --defaults-file=/home/mysql/data3306/my.cnf & /usr/local/mysql/bin/mysqld --defaults-file=/home/mysql/data3307/my.cnf --initialize --basedir=/usr/local/mysql/ --datadir=/home/mysql/data3307/data /usr/local/mysql/bin/mysqld_safe --defaults-file=/home/mysql/data3307/my.cnf & /usr/local/mysql/bin/mysqld --defaults-file=/home/mysql/data3309/my.cnf --initialize --basedir=/usr/local/mysql/ --datadir=/home/mysql/data3309/data /usr/local/mysql/bin/mysqld_safe --defaults-file=/home/mysql/data3309/my.cnf &
这里会生成默认密码,可以去error.log中看
//-----------------------------------------以上-数据库初始化完毕----
步骤9:
命令行中运行各个mysql实例:
/usr/local/mysql/bin/mysql -uroot -p -S /home/mysql/data3306/mysql.sock
输入初始化密码:
修改密码:
SET PASSWORD = PASSWORD('123456'); ALTER USER 'root'@'localhost' PASSWORD EXPIRE NEVER; FLUSH PRIVILEGES;
设置navicat可连接:
use mysql #访问mysql库 update user set host = '%' where user = 'root'; #使root能再任何host访问 FLUSH PRIVILEGES; #刷新
步骤10:
navicat连接数据库
停止节点:
查看进程号 :ps aux | grep mysql
以上是“linux如何安装mysql5.7的方法”这篇文章的所有内容,感谢各位的阅读!相信大家都有了一定的了解,希望分享的内容对大家有所帮助,如果还想学习更多知识,欢迎关注亿速云行业资讯频道!
免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。