Mysql5.7 ,Linux 环境安装
Mysql5.7 ,Linux 环境安装
1、下载mysql-5.7.8-rc-linux-glibc2.5-x86_64.tar.gz
链接:https://pan.baidu.com/s/1z4z8g6hzJWtNSqX96HxR8Q
提取码:mkp8
2、解压安装包:
进入安装包所在目录,执行命令:
tar -xzvf mysql-5.7.8-rc-linux-glibc2.5-x86_64.tar.gz
3、复制解压后的mysql目录到系统的本地软件目录:
注意:/opt/modules/mysql 必须是不存在的目录,如果mysql文件夹存在,就把mysql-5.7.8-rc-linux-glibc2.5-x86_64文件里面的数据复制进去。
执行命令:
cp mysql-5.7.8-rc-linux-glibc2.5-x86_64 /opt/modules/mysql -r
注意:目录结尾不要加/
chmod 777 -R /opt/modules
4、添加系统mysql组和mysql用户:
执行命令:groupadd mysql和useradd -r -g mysql mysql
5、安装数据库:
进入安装mysql软件目录:执行命令 cd /opt/modules/mysql
修改当前目录拥有者为mysql用户:执行命令 chown -R mysql:mysql ./
安装数据库:执行命令
./bin/mysqld --user=mysql --user=mysql --basedir=/opt/modules/mysql --datadir=/opt/modules/mysql/data/ --initialize
修改当前目录拥有者为root用户:执行命令 chown -R root:root ./
修改当前data目录拥有者为mysql用户:执行命令 chown -R mysql:mysql data
到此数据库安装完毕
6、复制mysql服务启动配置文件
cp /opt/modules/mysql/support-files/my-default.cnf /etc/my.cnf
更改配置文件:
-------------------------------------------------------------------
basedir = /opt/modules/mysql
datadir = /opt/modules/mysql/data/
port = 3306
# server_id = .....
socket = /tmp/mysql.sock
# Remove leading # to set options mainly useful for reporting servers.
# The server defaults are faster for transactions and fast SELECTs.
# Adjust sizes as needed, experiment to find the optimal values.
innodb_buffer_pool_size=6G
join_buffer_size = 256M
sort_buffer_size = 8M
key_buffer_size = 8M
max_allowed_packet = 100M
-------------------------------------------------------------------
7、复制mysql服务启动脚本及加入PATH路径
cp support-files/mysql.server /etc/init.d/mysqld
vi /etc/profile
MYSQL_HOME=/opt/modules/mysql
export PATH=$MYSQL_HOME/bin:$MYSQL_HOME/lib:$PATH
source /etc/profile
8、启动mysql服务并加入开机自启动(可选这个步骤,以后可以自己启动的)
service mysqld start
chkconfig --level 35 mysqld on
9、检查mysql服务是否启动
ss -lntp | grep 3306
10、修改mysql的root用户密码
MySQL5.7在安装完后,第一次启动时,会在root目录下生产一个随机的密码,文件名为.mysql_secret(隐藏文件)
vi /root/.mysql_secret
mysql -uroot -p
e+o?VkPu%69j
登录时需要用随机密码登录,然后通过以下命令修改密码 --不需要重启
SET PASSWORD = PASSWORD('root');
11、开启远程连接
mysql无法链接。。 !!!!
java.sql.SQLException: Access denied for user ‘root’@‘localhost’ (using password: YES)
1、mysql -u root -poperation123
2、use mysql;
3、select user,host from user;
4、select user,host from user where host=’%’;
如果数据为空则:update user set host=’%’ where host = ‘127.0.0.1’; (切记 root用户不要清空啊!!!! )
如果数据为空则:update user set host=’%’ where user = ‘root’; (切记 root用户不要清空啊!!!! )
5、select user,host from user where host!=’%’;
6、delete from user where host!=’%’;
7、select user,host from user;
8.Ctrl-C -- exit!
9、su - root
10、service mysqld restart
错误异常:
ERROR 2002 (HY000): Can’t connect to local MySQL server through socket ‘/tmp/mysql.sock’
解决方法:
由于mysql 默认的mysql.sock 是在/var/lib/mysql/mysql.sock,但linux系统总是去/tmp/mysql.sock查找,所以会报错
[root@localhost ~]# find / -name mysql.sock
/var/lib/mysql/mysql.sock
1.直接指定mysql通道
[root@localhost ~]# mysql --socket=/var/lib/mysql/mysql.sock
Welcome to the MySQL monitor. Commands end with ; or /g.
Your MySQL connection id is 2 to server version: 5.0.22
Type 'help;' or '/h' for help. Type '/c' to clear the buffer.
mysql>
2. 创建符号连接:
为mysql.sock增加软连接(相当于windows中的快捷方式)。
ln -s /var/lib/mysql/mysql.sock /tmp/mysql.sock
eg:
root@localhost ~]# mysql
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2)
[root@localhost ~]# ln -s /var/lib/mysql/mysql.sock /tmp/mysql.sock
[root@localhost ~]# mysql
Welcome to the MySQL monitor. Commands end with ; or /g.
Your MySQL connection id is 3 to server version: 5.0.22
Type 'help;' or '/h' for help. Type '/c' to clear the buffer.
mysql>
卸载msyql
1、查找以前是否装有mysql
命令:rpm -qa|grep -i mysql
可以看到mysql的两个包:
mysql-4.1.12-3.RHEL4.1
mysqlclient10-3.23.58-4.RHEL4.1
2、删除mysql
删除命令:rpm -e --nodeps 包名
( rpm -ev mysql-4.1.12-3.RHEL4.1 )
3、删除老版本mysql的开发头文件和库
find / -name mysql
查找结果如下:
[root@localhost ~]# find / -name mysql
删除对应的mysql目录
rm -rf /var/lock/subsys/mysql
rm -rf /opt/modules/mysql
rm -rf /home/hadoop/temp/mysql-5.7.8-rc-linux-glibc2.5-x86_64
rm -rf /opt/modules/mysql
4、查看mysql进程 使用 (kill -9) 删除
ps -ef|grep mysqld
kill -9 17614
忘记mysql root命令
1.关闭正在运行的MySQL
2.启动MySQL的安全模式,命令如下:
mysqld_safe --skip-grant-tables &
3 完成以后就可以不用密码进入MySQL了
mysql -u root -p
>use mysql
>update mysql.user set authentication_string=password('msstar') where user='root'
>flush privileges;
如果开启远程链接的时候,提示密码过期的话,重新设置。
SET PASSWORD = PASSWORD('msstar');
更多推荐
所有评论(0)