CentOS 7安装msyql(yum和Mysql5.7(解压缩版))

时间:2022-09-13 21:06:50

http://www.jianshu.com/p/bd01aac463d7

CentOS 7的yum源中貌似没有正常安装mysql时的mysql-sever文件,需要去官网上下载

 
# wget http://dev.mysql.com/get/mysql-community-release-el7-5.noarch.rpm
# rpm -ivh mysql-community-release-el7-5.noarch.rpm
# yum install mysql-community-server

成功安装之后重启mysql服务

 
# service mysqld restart

初次安装mysql是root账户是没有密码的

设置密码的方法

 
# mysql -uroot
mysql> set password for ‘root’@‘localhost’ = password('mypasswd');
mysql> exit


mysql授权

mysql> GRANT ALL PRIVILEGES ON *.* TO 'root'@'localhost'

->     IDENTIFIED BY 'some_pass' WITH GRANTOPTION;

首先要声明一下:一般情况下,修改MySQL密码,授权,是需要有mysql里的root权限的。

GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY '123456' WITH GRANT OPTION;


搞定!


Mysql5.7(解压缩版安装)转:http://blog.csdn.net/abudexiatian/article/details/51873387

 #### 1、下载安装包
http://dev.mysql.com/downloads/mysql/#downloads
推荐下载通用安装方法的TAR包

2.检查库文件是否存在,如有删除。

[root@localhost Desktop]$ rpm -qa | grep mysql
mysql-libs-5.1.52-1.el6_0.1.x86_64
[root@localhost ~]$ rpm -e mysql-libs-5.1.52.x86_64 --nodeps
[root@localhost ~]$
3.检查mysql组和用户是否存在,如无创建。
[root@localhost ~]$ cat /etc/group | grep mysql
mysql:x:490:
[root@localhost ~]$ cat /etc/passwd | grep mysql
mysql:x:496:490::/home/mysql:/bin/bash
以上为默认存在的情况,如无,执行添加命令:
[root@localhost ~]$groupadd mysql
[root@localhost ~]$useradd -r -g mysql mysql
//useradd -r参数表示mysql用户是系统用户,不可用于登录系统。
4.解压TAR包,更改所属的组和用户
[root@localhost ~]$ cd /usr/local/
[root@localhost local]$ tar xvf mysql-5.7.12-linux-glibc2.5-x86_64.tar
[root@localhost local]$ ls -l
total 1306432
-rwxr--r--. 1 root root 668866560 Jun 1 15:07 mysql-5.7.12-linux-glibc2.5-x86_64.tar
-rw-r--r--. 1 7161 wheel 638960236 Mar 28 12:54 mysql-5.7.12-linux-glibc2.5-x86_64.tar.gz
-rw-r--r--. 1 7161 wheel 29903372 Mar 28 12:48 mysql-test-5.7.12-linux-glibc2.5-x86_64.tar.gz
[root@localhost local]$ tar xvfz mysql-5.7.12-linux-glibc2.5-x86_64.tar.gz
[root@localhost local]$ mv mysql-5.7.12-linux-glibc2.5-x86_64 mysql
[root@localhost local]$ ls -l
total 1306436
drwxr-xr-x. 2 root root 4096 Dec 4 2009 bin
drwxr-xr-x. 2 root root 4096 Dec 4 2009 etc
drwxr-xr-x. 2 root root 4096 Dec 4 2009 games
drwxr-xr-x. 2 root root 4096 Dec 4 2009 include
drwxr-xr-x. 2 root root 4096 Dec 4 2009 lib
drwxr-xr-x. 3 root root 4096 Dec 2 14:36 lib64
drwxr-xr-x. 2 root root 4096 Dec 4 2009 libexec
drwxr-xr-x. 9 7161 wheel 4096 Mar 28 12:51 mysql
-rwxr--r--. 1 root root 668866560 Jun 1 15:07 mysql-5.7.12-linux-glibc2.5-x86_64.tar
-rw-r--r--. 1 7161 wheel 638960236 Mar 28 12:54 mysql-5.7.12-linux-glibc2.5-x86_64.tar.gz
-rw-r--r--. 1 7161 wheel 29903372 Mar 28 12:48 mysql-test-5.7.12-linux-glibc2.5-x86_64.tar.gz
drwxr-xr-x. 2 root root 4096 Dec 4 2009 sbin
drwxr-xr-x. 6 root root 4096 Dec 2 14:36 share
drwxr-xr-x. 2 root root 4096 Dec 4 2009 src
[root@localhost local]$ chown -R mysql mysql/
[root@localhost local]$ chgrp -R mysql mysql/
[root@localhost local]$ cd mysql/
5.安装和初始化数据库
[root@localhost mysql]$ bin/mysql_install_db --user=mysql --basedir=/usr/local/mysql/ --datadir=/usr/local/mysql/data/
2016-06-01 15:23:25 [WARNING] mysql_install_db is deprecated. Please consider switching to mysqld --initialize
2016-06-01 15:23:30 [WARNING] The bootstrap log isn't empty:
2016-06-01 15:23:30 [WARNING] 2016-06-01T22:23:25.491840Z 0 [Warning] --bootstrap is deprecated. Please consider using --initialize instead
2016-06-01T22:23:25.492256Z 0 [Warning] Changed limits: max_open_files: 1024 (requested 5000)
2016-06-01T22:23:25.492260Z 0 [Warning] Changed limits: table_open_cache: 431 (requested 2000)
[root@localhost mysql]$

[root@localhost mysql]$ cp -a ./support-files/my-default.cnf /etc/my.cnf
[root@localhost mysql]$ cp -a ./support-files/mysql.server /etc/init.d/mysqld

[root@localhost bin]# /etc/init.d/mysqld restartShutting down MySQL..2016-06-01T22:27:50.498694Z mysqld_safe mysqld from pid file /usr/local/mysql/data/localhost.localdomain.pid ended
SUCCESS!
Starting MySQL. SUCCESS!
[1]+ Done ./mysqld_safe --user=mysql
[root@localhost bin]$
//设置开机启动
[root@localhost bin]$ chkconfig --level 35 mysqld on
[root@localhost bin]$
6.初始化密码
[root@localhost bin]$ cat /root/.mysql_secret 
# Password set for user 'root@localhost' at 2016-06-01 15:23:25
,xxxxxR5H9
配置环境变量
vi /etc/profile
export PATH=$PATH:/usr/local/mysql/bin
#使环境生效
source /etc/profile
执行命令
# ln -s /usr/local/mysql/bin/mysql /usr/bin


mysql -uroot -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.7.12

Copyright (c) 2000, 2016, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> SET PASSWORD = PASSWORD('123456');
Query OK, 0 rows affected, 1 warning (0.00 sec)

mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)

7.添加远程访问权限
mysql> use mysql; 
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A


Database changed
mysql> update user set host = '%' where user = 'root';
Query OK, 1 row affected (0.00 sec)
Rows matched: 1 Changed: 1 Warnings: 0


mysql> select host, user from user;
+-----------+-----------+
| host | user |
+-----------+-----------+
| % | root |
| localhost | mysql.sys |
+-----------+-----------+
//重启生效
/etc/init.d/mysqld restart

5.6安装
http://blog.itpub.net/29485627/viewspace-2135947/

windows安装
http://blog.csdn.net/u010094934/article/details/77044038
http://www.cnblogs.com/zhangshisanlang/p/5780862.html
http://blog.csdn.net/mhmyqn/article/details/17043921