mysql解压版安装过程,之前安装mysql一直用linux yum和rpm方式。今天试了下tar包方式有点麻烦记录下
1.安装lrzsz-0.12.20-27.1.el6.x86_64.rpm方便操作,用ftp工具上传
2.rz传输文件mysql-5.6.46-linux-glibc2.12-x86_64.tar.gz,tar -xzvf解压
3.mv mysql-5.6.46-linux-glibc2.12-x86_64 mysql
4.cd /usr/local
5.mv mysql /usr/local/
6.groupadd mysql
7.useradd -g mysql mysql
8.cd /usr/local/mysql/data mkdir mysql
9.cd ..
10. ./scripts/mysql_install_db --user=mysql --datadir=/usr/local/mysql/data/mysql (安装并指定用户和data文件夹位置)
11.cp support-files/mysql.server /etc/init.d/mysqld (复制mysql到服务自启动里面)
12.chmod 755 /etc/init.d/mysqld (修改权限为755)
13.cp support-files/my-default.cnf /etc/my.cnf(复制配置文件到etc下,选择覆盖掉之前的配置文件)
14.vim /etc/init.d/mysqld (修改启动脚本)
basedir=/usr/local/mysql/
datadir=/usr/local/mysql/data/mysql
15.service mysqld start (启动服务)
16.mysql -uroot
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2) 文件下缺少mysql的socket文件负责通信的
17.cd /tmp 发现下面有sock文件
18.此时有两种方式。
1)把sock文件挪动到对应目录下
2)在/etc/my.cnf修改配置文件 我选择了第二种,因为顺便可以调整下UTF参数什么
19.vi /etc/my.cnf贴进
[mysqld]
datadir=/usr/local/mysql/data/mysql/
socket=/tmp/mysql.sock
[client]
default-character-set=utf8
socket=/storage/db/mysql/mysql.sock
[mysql]
default-character-set=utf8
socket=/tmp/mysql.sock
重启mysql
20. mysql -uroot (第一次进去不用mysql密码)
21.use mysql;
set password for root@localhost = password('123456');(修改初始化密码)
22.出现密码错误(不知道是不是自己按错了)
23.export MYSQL_HOME=/usr/local/mysql/
PATH=$JAVA_HOME/bin:$MYSQL_HOME/bin (追加到环境变量)
24.vi /etc/my.cnf
找到[mysqlId],在之后添skip-grant-tables(跳过授权表),此时重启 MySQL服务,打开命令行,就可以使用空密码登陆了。(记得重启服务)
25.service mysqld restart(重启服务)
26.update user set password=PASSWORD('123456') where user='root';flush privileges;
27.set password for 'root'@'localhost'=password('123456');flush privileges;
28.GRANT ALL PRIVILEGES ON *.* TO 'root'@'localhost' IDENTIFIED BY '123456' WITH GRANT OPTION; flush privileges;
29.GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY '123456' WITH GRANT OPTION;flush privileges; (%表示全部地址一起赋值了)
30.vi /etc/my.cnf 去掉skip-grant-tables
31.重启mysql服务(此刻localhost已经有权限进入,装了两台不知道为什么会出现这种问题,这个错误用这种赋权方法就好了)
32.mysql -uroot -p 键入密码成功进入