Linux安装mysql5.6
一.下载安装包
选择对应的包 如下5.6包
下载官方 Mysql 包
https://downloads.mysql.com/archives/community/
二.创建mysql用户组和mysql用户
groupadd mysql && useradd -r -g mysql mysql
上传解压,并初始化
#解压软件包并改名 tar -zxvf mysql-5.6.44-linux-glibc2.12-x86_64.tar.gz -C /usr/local/ mv /usr/local/mysql-5.6.44-linux-glibc2.12-x86_64 /usr/local/mysql #创建数据目录并赋予权限 mkdir -p /data/mysql chown mysql:mysql -R /data/mysql #修改配置文件 cat > /etc/my.cnf << EOF #mysql配置文件 [mysqld] port=3306 user=mysql basedir=/usr/local/mysql datadir=/data/mysql socket=/tmp/mysql.sock log-error=/data/mysql/mysql.err pid-file=/data/mysql/mysql.pid #character config character_set_server=utf8mb4 symbolic-links=0 explicit_defaults_for_timestamp=true default-storage-engine=INNODB innodb_buffer_pool_size = 512M innodb_log_file_size = 512M wait_timeout=2880000 interactive_timeout = 2880000 max_allowed_packet = 100M innodb_lock_wait_timeout=500 innodb_large_prefix=on innodb_file_format=BARRACUDA max_connections=300
lower_case_table_names=1 EOF #安装初始化依赖 yum -y install autoconf make perl #执行初始化 cd /usr/local/mysql/scripts/ ./mysql_install_db --defaults-file=/etc/my.cnf --basedir=/usr/local/mysql/ --datadir=/data/mysql/ --user=mysql
其中: --defaults-file 指定配置文件
–basedir指定Mysql安装目录
–datadir指定数据目录
–user所属用户
四.启动mysql
cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysql service mysql start
五.修改密码
[root@bbb scripts]# /usr/local/mysql/bin/mysql -u root Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 1 Server version: 5.6.44 MySQL Community Server (GPL) Copyright (c) 2000, 2019, Oracle and/or its affiliates. All rights reserved. Oracle is a registered trademark of Oracle Corporation and/or its affiliates. Other names may be trademarks of their respective owners. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement. mysql> update mysql.user set Password=password('mysql') where Host='localhost' and User='root'; Query OK, 1 row affected (0.00 sec) Rows matched: 1 Changed: 1 Warnings: 0 mysql> flush privileges; Query OK, 0 rows affected (0.00 sec) mysql> exit Bye
六.创建可以远程连接的账号
[root@iZbp1cebowmh8sflwg89tcZ /]# /usr/local/mysql/bin/mysql -u root -p Enter password: Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 11 Server version: 5.6.44 MySQL Community Server (GPL) Copyright (c) 2000, 2019, Oracle and/or its affiliates. All rights reserved. Oracle is a registered trademark of Oracle Corporation and/or its affiliates. Other names may be trademarks of their respective owners. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement. mysql> CREATE USER 'root'@'%' IDENTIFIED BY 'Aa@123456'; ERROR 1396 (HY000): Operation CREATE USER failed for 'root'@'%' mysql> CREATE USER 'tcc'@'%' IDENTIFIED BY 'Aa@123456'; Query OK, 0 rows affected (0.00 sec) mysql> GRANT ALL PRIVILEGES ON *.* TO 'tcc'@'%' WITH GRANT OPTION; Query OK, 0 rows affected (0.00 sec) mysql> FLUSH PRIVILEGES; Query OK, 0 rows affected (0.00 sec)
七.创建账号可以服务器本地登录
mysql> grant all privileges on *.* to tcc@'localhost' identified by 'Aa@123456';
mysql> flush privileges;
八.项目日志报错连接不上,记得看tomcat日志,报错“java.sql.SQLException: Access denied for user 'shjz'@'iZvy200r0bki10ncagpkdnZ' (using password: YES)”
解决措施
grant all privileges on *.* to shjz@'iZvy200r0bki10ncagpkdnZ' identified by 'Aa@123456'; flush privileges; service mysql restart;