您的位置:首页 > 运维架构 > Linux

linux安装mysql5.7.19

2018-03-07 14:03 141 查看
1:下载[root@localhostsoft]# wget https://cdn.mysql.com//Downloads/MySQL-5.7/mysql-5.7.19-linux-glibc2.12-x86_64.tar.gz·      12:解压文件[root@dbserver /]# tar -xzvfmysql-5.7.19-linux-glibc2.12-x86_64.tar.gz -C /usr/local/·      13修改文件[root@dbserverlocal]# mv  mysql-5.7.19-linux-glibc2.12-x86_64 mysql·      14:检查库文件是否有删除,若有便删除(linux系统自带的)   [root@dbserver mysql]# rpm -qa | grep mysql·      1  删除  [root@dbserver mysql]# rpm -e --nodepsmysql-libs-5.1.73-3.el6_5.x86_64·      15:检查mysql组和用户是否存在,如无创建     [root@dbserver ~]# cat /etc/group | grep mysql   [root@dbserver ~]# cat /etc/passwd |grep mysql·      1·      2创建   [root@dbserver ~]#groupadd mysql   [root@dbserver ~]#useradd -r -g mysql mysql       //useradd -r参数表示mysql用户是系统用户,不可用于登录系统6:在mysql下添加data目录     [root@dbserver mysql]# mkdir data7:更改mysql目录下所有的目录及文件夹所属组合用户[root@dbserver mysql]# cd /usr/local/[root@dbserverlocal]# chown -R mysqlmysql/[root@dbserverlocal]# chgrp -R mysqlmysql/[root@dbserverlocal]# cd mysql/[root@dbserver mysql]# ls -ltotal 40drwxr-xr-x.  2 mysql mysql  4096 Aug 3116:45 bin-rw-r--r--. 1 mysql mysql 17987 Jun 2222:13 COPYINGdrwxr-xr-x.  2 mysql mysql     6 Aug 3116:48 datadrwxr-xr-x.  2 mysql mysql    52 Aug 3116:45 docsdrwxr-xr-x.  3 mysql mysql  4096 Aug 3116:44 includedrwxr-xr-x.  5 mysql mysql  4096 Aug 3116:45 libdrwxr-xr-x.  4 mysql mysql    28 Aug 3116:45 man-rw-r--r--. <
101db
span style="color:#006666;">1 mysql mysql  2478 Jun 2222:13 READMEdrwxr-xr-x. 28 mysqlmysql  4096 Aug 3116:45 sharedrwxr-xr-x.  2 mysql mysql    86 Aug 3116:45 support-files8:安装和初始化数据库 
安装  ./mysqld --initialize--user=mysql --basedir=/usr/local/mysql/--datadir=/usr/local/mysql/data/2017-08-31T08:50:23.910440Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp serveroption (see documentation for more details).2017-08-31T08:50:23.910635Z 0 [ERROR] Can't find error-message file '/usr/local/mysql/--datadir=/usr/local/mysql/data/share/errmsg.sys'.Check error-message file location and 'lc-messages-dir' configuration directive.2017-08-31T08:50:24.709286Z 0 [Warning] InnoDB: New log files created,LSN=457902017-08-31T08:50:24.767540Z 0 [Warning] InnoDB: Creating foreign keyconstraint system tables.2017-08-31T08:50:24.892629Z 0 [Warning] No existing UUID has been found,so we assume that this isthefirst time that this server has been started. Generating anew UUID: 6e083b8f-8e29-11e7-88b1-005056b427be.2017-08-31T08:50:24.895674Z 0 [Warning] Gtid table isnot ready to be used. Table 'mysql.gtid_executed'cannot be opened.2017-08-31T08:50:24.896645Z 1 [Note] A temporary password is generated for root@localhost: gFamcspKm2+u报错[ERROR] Can’t find error-message file ‘/usr/local/mysql/–datadir=/usr/local/mysql/data/share/errmsg.sys’.Check error-message file location and ‘lc-messages-dir’ con解决[root@dbserver bin]# ./mysqld --initialize--user=mysql --basedir=/usr/local/mysql/ --datadir=/usr/local/mysql/data/ --lc_messages_dir=/usr/local/mysql/share--lc_messages=en_US2017-08-31T09:00:54.941514Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestampserveroption (see documentation for more details).2017-08-31T09:00:56.364312Z 0 [Warning] InnoDB: Newlog files created, LSN=457902017-08-31T09:00:56.602211Z 0 [Warning] InnoDB: Creating foreign keyconstraint system tables.2017-08-31T09:00:56.668145Z 0 [Warning] No existing UUID has been found,so we assume that this is the first time that this server has been started. Generating a new UUID: e69986d2-8e2a-11e7-a335-005056b427be.2017-08-31T09:00:56.671464Z 0 [Warning] Gtid table isnot ready to be used. Table 'mysql.gtid_executed' cannot be opened.2017-08-31T09:00:56.672453Z 1 [Note] A temporary password is generated for root@localhost: qfuqvCsHb2!.9配置my.cnf 
接下来进入/usr/local/mysql/support-files/目录下 
查看是否存在my-default.cnf文件,如果存在直接copy到/etc/my.cnf文件中   [root@dbserver mysql]# cp -a ./support-files/my-default.cnf/etc/my.cnf如果不存在my-default.cnf文件,则在/etc/目录下创建my.cnf,并写入以下内容#[mysql] #basedir=/usr/local/mysql/  #datadir=/usr/local/mysql/data/ 10启动服务[root@dbserver mysql]# cd bin/[root@dbserver bin]# ./mysqld_safe --user=mysql &[2] 10436[root@dbserver bin]# Logging to '/var/log/mysql/mysql.log'.2017-08-31T09:52:15.806633Z mysqld_safe Starting mysqld daemonwith databases from /var/lib/mysql2017-08-31T09:52:16.292949Z mysqld_safe mysqld from pid file/var/run/mysql/mysql.pid ended11将mysqld服务加入开机自启动项。 
将{mysql}/ support-files/mysql.server 拷贝为/etc/init.d/mysql并设置运行权限,这样就可以使用service mysql命令启动/停止服务, 
否则就只能使用{mysql}/bin/mysqld_safe &命令来启动服务 
还需要把mysql.server中basedir的相关路径,改为自定义的路径,默认路径是/usr/local/mysql[root@dbserver support-files]# cp mysql.server /etc/init.d/mysql  [root@dbserver support-files]# chmod +x /etc/init.d/mysql -- 把mysql注册为开机启动的服务[root@dbserver support-files]# chkconfig --add mysql  -- 查看是否添加成功[root@dbserver support-files]# chkconfig --list mysql  Note: This output shows SysV services only anddoesnot include native     systemd services. SysV configuration data might be overridden by native     systemd configuration.      If you want to list systemd services use 'systemctllist-unit-files'.     To see services enabled on particulartarget use     'systemctl list-dependencies [target]'. mysql           0:off   1:off  2:on    3:on    4:on    5:on   6:off 12启动服务[root@dbserver bin]# service mysql startStarting MySQL.Logging to '/var/log/mysql/mysql.log'. ERROR! The server quit without updating PID file(/var/lib/mysql/dbserver.pid).解决[root@dbserver mysql]# rm /etc/my.cnfrm: remove regular file '/etc/my.cnf'? y[root@dbserver mysql]# /etc/init.d/mysql start Starting MySQL.Logging to '/usr/local/mysql/data/dbserver.err'. SUCCESS! [root@dbserver mysql]# service mysql startStarting MySQL SUCCESS!13登录mysql[root@dbserver bin]# ./mysql -u root -p密码是第八步产生的密码14设置密码mysql> set password=password("123456");Query OK, 0 rows affected, 1 warning (0.00sec)注意不要使用单引号,为什么?你自己试试就知道了15设置远程登录权限mysql>  grant all privileges on*.*to'root' @' localhost' identified by123456;Query OK, 0rows affected, 1 warning (0.00 sec) mysql> flush privileges;Query OK, 0rows affected (0.06 sec) mysql> quitByeMySQL> updateuser set host='%' where user = 'root'; 
ERROR 1062(23000): Duplicate entry '%-root' for key 'PRIMARY' 
然后查看了下数据库的host信息如下: 
MySQL> selecthost from user where user = 'root'; 
+-----------------------+ 
| host | 
+-----------------------+ 
| % | 
| 127.0.0.1| 
|localhost.localdomain | 
+-----------------------+ 
3 rows in set(0.00 sec) 
host已经有了%这个值,所以直接运行命令: 
复制代码代码如下:

MySQL>flushprivileges; 

再用MySQL administrator连接...成功!!

第二种安装方式:
Yum 安装方法,执行命令如下即可:yum  install mysql-server mysql-devel mysql -y
启动:/etc/init.d/mysqld restart
进入mysql,执行:mysql
Mysql 忘记密码如何破解:
首行关闭mysql进程,然后输入命令:mysqld_safe --skip-grant-tables & 
跳过密码启动mysql
然后进入mysql数据库,执行:use msyql 
修改密码即可:
update user set password=password("123456") where user="root";

设置远程登录权限
mysql>  grant all privileges on*.*to'root' @' localhost' identified by123456;Query OK, 0rows affected, 1 warning (0.00 sec) mysql> flush privileges;Query OK, 0rows affected (0.06 sec) mysql> quit
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: