工具 初始 serve warning 区别 nds all ted files
- [[email protected] ~]# rpm -qa | grep -i mysql
- mysql-libs-5.1.71-1.el6.x86_64
- [[email protected] ~]# rpm -e --nodeps mysql-libs-5.1.71-1.el6.x86_64
- [[email protected] ~]# rpm -qa | grep -i mysql
- rpm -e --noscripts MySQL-client-5.5.25a-1.rhel5
- rm -fr 删除文件
- [[email protected] ~]# tar -zxvf mysql-5.7.17-linux-glibc2.5-x86_64.tar.gz -C /data/
- [[email protected] ~]# mv mysql-5.7.17-linux-glibc2.5-x86_64/ mysql-5.7.17
- [[email protected] mysql-5.7.17]# groupadd mysql
- [[email protected] mysql-5.7.17]# useradd -r -g mysql mysql
- [[email protected] data]#mkdir / data / mysql - 5.7 / data
将mysql及其下所有的目录所有者和组均设为mysql:
- [[email protected] mysql-5.7]# chown -R mysql:mysql /data/mysql-5.7/
- [[email protected] mysql-5.7]# chmod 755 /data/mysql-5.7./
- [[email protected] bin]#. / mysqld--initialize--user = mysql--datadir = /data/mysql - 5.7 / data--basedir = /data/mysql - 5.7
初始化完成记录下初始密码,登录数据库要用到
- [email protected]: TsYB;K9rwrK6
将mysql/support-files下的my-default.cnf改名为my.cnf,拷到/etc下(或者考到{mysql}下,然后作一个软链接到/etc下):
- [[email protected] support-files]# cp /data/mysql-5.7.17/support-files/my-default.cnf /etc/my.cnf
修改/etc/my.cnf中关键配置:
- [[email protected] support-files]# vim /etc/my.cnf
- [mysqld]
- basedir = /data/mysql-5.7.17
- datadir = /data/mysql-5.7.17/data
- port = 3306
- socket = /data/mysql-5.7.17/tmp/mysql.sock
注意,tmp目录不存在,请创建之。
- [[email protected] data]#mkdir / data / mysql - 5.7.17 / tmp
- [[email protected] mysql-5.7.17]# chown mysql:mysql /data/mysql-5.7/
- [[email protected] data]# chmod 755 /data/mysql-5.7.17/
- [[email protected] bin]#. / mysqld_safe &
注:在这个启动脚本里已默认设置--user=mysql;在脚本末尾加&表示设置此进程为后台进程,区别就是在控制台输入bg,即可将当前进程转入后台,当前shell可进行其他操作。
可能会报错:
- 2017-10-11T13:04:21.482778Z mysqld_safe Logging to ‘/data/mysql-5.7/data/centos.xd.err‘.
- 2017-10-11T13:04:21.485731Z mysqld_safe The file /usr/local/mysql/bin/mysqld
- does not exist or is not executable. Please cd to the mysql installation
- directory and restart this script from there as follows:
- ./bin/mysqld_safe&
- See http://dev.mysql.com/doc/mysql/en/mysqld-safe.html for more information
说明:mysqld_safe启动脚本默认的从/usr/local/mysql目录中读取另外一个启动脚本mysqld,因为我的安装目录为/data/mysql-5.17/bin/mysqld,所以找不到相关文件。
解决方法:
- [[email protected] mysql-5.7]# mkdir -p /usr/local/mysql/bin/
- [[email protected] mysql-5.7]# ln -s /data/mysql-5.7/bin/mysqld /usr/local/mysql/bin/
将{mysql}/ support-files/mysql.server 拷贝为/etc/init.d/mysql并设置运行权限
- [[email protected] data]# cp /data/mysql-5.7/support-files/mysql.server /etc/init.d/mysql
- [[email protected] data]#chmod +x /etc/init.d/mysql
- [[email protected] data]# / etc / init.d / mysql start
可能会出现错误:
1:Starting MySQL.Logging to ‘/data/mysqldata/localhost.localdomain.err’.
ERROR! The server quit without updating PID file (/data/mysqldata/localhost.localdomain.pid).
bin/mysqld –initialize –user=mysql 是关键,再重新安装下
2:MySQL [ERROR] Table ‘mysql.user‘ doesn‘t exist
检查/etc/my.cnf配置是否正确datadir
检查后重新启动
- [[email protected] mysql-5.7]# /etc/init.d/mysql start
- Starting MySQL. SUCCESS!
- [[email protected]~]#mysql - uroot - p
可能会出现错误:
1:-bash: mysql: command not found
将mysql/bin/mysql命令 链接到usr/bin/mysql x
- [[email protected]~]#ln - s / usr / local / mysql / bin / mysql / usr / bin / mysql
2:ERROR 2002 (HY000): Can‘t connect to local MySQL server through socket ‘/tmp/mysql.sock‘ (2)
则需要在在my.cnf中填加:
[client]
socket = /data/mysql-5.7/tmp/mysql.sock
如果不行则使用软链接:
- [[email protected] tmp]#ln - s / data / mysql - 5.7 / tmp / mysql.sock / tmp / mysql.sock
启动成功
- [[email protected] mysql-5.7]# mysql -uroot -p
- Enter password: 输入初始化数据库时记录的密码
- Welcome to the MySQL monitor. Commands end with ; or \g.
- Your MySQL connection id is 3
- Server version: 5.7.17 MySQL Community Server (GPL)
设置root用户密码
- mysql> set password=password(‘123456‘);
- Query OK, 0 rows affected, 1 warning (0.03 sec)
给root账户赋予全部权限
- mysql> grant all privileges on *.* to [email protected]‘localhost‘ identified by ‘123456‘;
- Query OK, 0 rows affected, 1 warning (0.00 sec)
刷新
- mysql> flush privileges;
- Query OK, 0 rows affected (0.00 sec)
退出mysql
- mysql > exit;
- Bye
- #chkconfig --add mysql
- 使用范例:
- chkconfig --list #列出所有的系统服务
- chkconfig --add httpd #增加httpd服务
- chkconfig --del httpd #删除httpd服务
- chkconfig --level httpd 2345 on #设置httpd在运行级别为2、3、4、5的情况下都是on(开启)的状态
- chkconfig --list #列出系统所有的服务启动情况
- chkconfig --list mysqld #列出mysqld服务设置情况
- chkconfig --level 35 mysqld on #设定mysqld在等级3和5为开机运行服务,--level 35表示操作只在等级3和5执行,on表示启动,off表示关闭
- chkconfig mysqld on #设定mysqld在各等级为on,“各等级”包括2、3、4、5等级
- 如何增加一个服务:
- 1.服务脚本必须存放在/etc/ini.d/目录下;
- 2.chkconfig --add servicename
- 在chkconfig工具服务列表中增加此服务,此时服务会被在/etc/rc.d/rcN.d中赋予K/S入口了;
- 3.chkconfig --level 35 mysqld on
- 修改服务的默认启动等级。
- [[email protected] mysql-5.7]# /etc/init.d/mysql start
- [[email protected] mysql-5.7]# /etc/init.d/mysql stop
- 或:
- [[email protected] mysql-5.7]# service mysql stop
- Shutting down MySQL.. SUCCESS!
- [[email protected] mysql-5.7]# service mysql start
- Starting MySQL. SUCCESS!
- [[email protected] mysql-5.7]# whereis mysql
- mysql: /usr/bin/mysql /usr/lib64/mysql /usr/local/mysql /usr/share/mysql
- [[email protected] mysql-5.7]# which mysql
- /usr/bin/mysql
Linux安装mysql-5.7.17
来源: http://www.bubuko.com/infodetail-2347143.html