linux mysql 安装记录
#elasticsearch 创建目录
mkdir /disk/elasticsearch
mkdir /disk/elasticsearch/conf
mkdir /disk/elasticsearch/data
mkdir /disk/elasticsearch/logs
mkdir /disk/elasticsearch/plugins
#授权
chmod -R 777 /disk/elasticsearch/logs
chmod -R 777 /disk/elasticsearch/data
chmod -R 777 /disk/elasticsearch/plugins
#kibana 创建目录
mkdir /disk/kibana
mkdir /disk/kibana/conf
mkdir /disk/kibana/data
mkdir /disk/kibana/logs
#授权
chmod -R 777 /disk/kibana/data
chmod -R 777 /disk/kibana/logs
#logstash 创建目录
mkdir /disk/logstash
mkdir /disk/logstash/conf
mkdir /disk/logstash/data
mkdir /disk/logstash/logs
mkdir /disk/logstash/patterns
#授权
chmod -R 777 /disk/logstash/data
chmod -R 777 /disk/logstash/logs
解压
tar xzvf mysql-5.7.24-linux-glibc2.12-x86_64.tar.gz
移动位置
mv mysql-5.7.24-linux-glibc2.12-x86_64 /usr/local/mysql
添加用户组
groupadd mysql
useradd -r -g mysql mysql
授权
chown -R mysql:mysql /disk/mysql
chmod -R 755 /disk/mysql
编译安装并初始化mysql 需要记住初始化密码
cd /usr/local/mysql/bin
./mysqld --initialize --user=mysql --datadir=/disk/mysql/data --basedir=/disk/mysql
编辑配置
vim /etc/my.cnf
datadir=/usr/local/mysql/data
port = 3306 //端口
sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES
symbolic-links=0
max_connections=400
innodb_file_per_table=1 //是否将每个表的数据单独存储,1表示单独存储;0表示关闭独立表空间,可以通过查看数据目录,查看文件结构的区别;
lower_case_table_names=1 //是否区分大小写,1表示存储时表名为小写,操作时不区分大小写;0表示区分大小写;不能动态设置,修改后,必须重启才能生效:
character_set_server=utf8 //设置数据库默认字符集,如果不设置默认为latin1
启动mysql服务
/usr/local/mysql/support-files/mysql.server start
添加软连接
ln -s /usr/local/mysql/support-files/mysql.server /etc/init.d/mysql
ln -s /usr/local/mysql/bin/mysql /usr/bin/mysql
service mysql restart
登录
mysql -u root -p
之前临时密码
修改密码
set password for root@localhost = password('123456');
开放远程连接
update user set user.Host='%' where user.User='root';
flush privileges;
遇到问题
1)文件夹无权限 文件夹不存在
解决方法 创建文件并授权
2)无法启动
修改配置文件
vi /usr/local/mysql/support-files/mysql.server
$bindir/mysqld_safe --datadir="$datadir" --pid-file="$mysqld_pid_file_path" $other_args >/dev/null &
修改为
$bindir/mysqld_safe --user=root --datadir="$datadir" --pid-file="$mysqld_pid_file_path" $other_args >/dev/null &
添加 --user=root
解决问题
3)输入密码是报错
Can't connect to local MySQL server through socket '/tmp/mysql.sock
添加软连接 解决
ln -s /var/lib/mysql/mysql.sock /tmp
4)外网无法访问
防火墙打开端口3306 即可解决
firewall-cmd --zone=public --add-port=3306/tcp --permanent