Linux下rpm方式安装mysql
1.第一步
从百度云盘里获取压缩包
链接: https://pan.baidu.com/s/1bqb1A8n 密码: p5gb
2.第二步
使用Xshell连接服务器
首先将下载好的tar压缩文件放到服务器的文件夹中
解压.tar压缩文件
#tar -xf ***.tar (文件名省略)
注意:安装前先查询系统是否以及安装mysql,如果有需要将之前的mysql删除彻底。
3.首先安装MySQL-server-5.6.22-1.el6.x86_64.rpm(对于顺序有要求)
开始安装server端
#rpm -ivh MySQL-server-5.6.22-1.el6.x86_64.rpm
安装完成之后,会有提示:
提示一:安装好mysql-server之后会随机生成一个root账户的密码,保存在: /root/.mysql_secret 这里
提示二:安装好mysql-server之后第一次连接mysql的时候需要去修改一下这个默认的密码
在确定好这之后,需要执行命令:find / -name mysql 来寻找mysql-server的安装位置,如下:
/etc/logrotate.d/mysql
/etc/rc.d/init.d/mysql ---- 启动文件
/usr/share/mysql ---- 包含my-default.cnf文件
/usr/bin/mysql
/usr/lib/mysql
/var/lib/mysql ---- 数据库文件存放目录
然后再执行: find / -name my.cnf 寻找mysql-server 的配置文件的位置,如下:
/usr/my.cnf
然后启动mysql-server,执行: /etc/init.d/mysql start
提示启动成功之后执行:ps -el | grep mysql
系统会列出mysqld的相关进程信息,说明mysql-server安装成功!
例子:安装完成后,提示信息(里面包含有用信息)
1 [root@i-B6DFC927 test]# rpm -ivh MySQL-server-5.6.22-1.el6.x86_64.rpm2 Preparing... ########################################### [100%]3 1:MySQL-server ########################################### [100%]4 warning: user mysql does not exist - usingroot5 warning: group mysql does not exist - usingroot6 2016-07-26 14:59:11 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation formore details).7 2016-07-26 14:59:11 30041 [Note] InnoDB: Using atomics to refcount buffer pool pages8 2016-07-26 14:59:11 30041 [Note] InnoDB: The InnoDB memory heap isdisabled9 2016-07-26 14:59:11 30041[Note] InnoDB: Mutexes and rw_locks use GCC atomic builtins10 2016-07-26 14:59:11 30041 [Note] InnoDB: Memory barrier isnot used11 2016-07-26 14:59:11 30041 [Note] InnoDB: Compressed tables use zlib 1.2.3
12 2016-07-26 14:59:11 30041[Note] InnoDB: Using Linux native AIO13 2016-07-26 14:59:11 30041[Note] InnoDB: Using CPU crc32 instructions14 2016-07-26 14:59:11 30041 [Note] InnoDB: Initializing buffer pool, size = 128.0M
15 2016-07-26 14:59:11 30041[Note] InnoDB: Completed initialization of buffer pool16 2016-07-26 14:59:11 30041 [Note] InnoDB: The first specified data file ./ibdata1 did not exist: a new database to be created!
17 2016-07-26 14:59:11 30041 [Note] InnoDB: Setting file ./ibdata1 size to 12MB18 2016-07-26 14:59:11 30041[Note] InnoDB: Database physically writes the file full: wait...19 2016-07-26 14:59:12 30041 [Note] InnoDB: Setting log file ./ib_logfile101 size to 48MB20 2016-07-26 14:59:13 30041 [Note] InnoDB: Setting log file ./ib_logfile1 size to 48MB21 2016-07-26 14:59:14 30041 [Note] InnoDB: Renaming log file ./ib_logfile101 to ./ib_logfile022 2016-07-26 14:59:14 30041 [Warning] InnoDB: New log files created, LSN=45781
23 2016-07-26 14:59:14 30041 [Note] InnoDB: Doublewrite buffer not found: creating new
24 2016-07-26 14:59:14 30041[Note] InnoDB: Doublewrite buffer created25 2016-07-26 14:59:14 30041 [Note] InnoDB: 128rollback segment(s) are active.26 2016-07-26 14:59:14 30041[Warning] InnoDB: Creating foreign key constraint system tables.27 2016-07-26 14:59:14 30041[Note] InnoDB: Foreign key constraint system tables created28 2016-07-26 14:59:14 30041[Note] InnoDB: Creating tablespace and datafile system tables.29 2016-07-26 14:59:14 30041[Note] InnoDB: Tablespace and datafile system tables created.30 2016-07-26 14:59:14 30041 [Note] InnoDB: Waiting forpurge to start31 2016-07-26 14:59:14 30041 [Note] InnoDB: 5.6.22 started; log sequence number 0
32 A random root password has been set. You will find it in '/root/.mysql_secret'.33 2016-07-26 14:59:16 30041[Note] Binlog end34 2016-07-26 14:59:16 30041[Note] InnoDB: FTS optimize thread exiting.35 2016-07-26 14:59:16 30041[Note] InnoDB: Starting shutdown...36 2016-07-26 14:59:17 30041 [Note] InnoDB: Shutdown completed; log sequence number 1625977
37
38
39 2016-07-26 14:59:17 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation formore details).40 2016-07-26 14:59:17 30063 [Note] InnoDB: Using atomics to refcount buffer pool pages41 2016-07-26 14:59:17 30063 [Note] InnoDB: The InnoDB memory heap isdisabled42 2016-07-26 14:59:17 30063[Note] InnoDB: Mutexes and rw_locks use GCC atomic builtins43 2016-07-26 14:59:17 30063 [Note] InnoDB: Memory barrier isnot used44 2016-07-26 14:59:17 30063 [Note] InnoDB: Compressed tables use zlib 1.2.3
45 2016-07-26 14:59:17 30063[Note] InnoDB: Using Linux native AIO46 2016-07-26 14:59:17 30063[Note] InnoDB: Using CPU crc32 instructions47 2016-07-26 14:59:17 30063 [Note] InnoDB: Initializing buffer pool, size = 128.0M
48 2016-07-26 14:59:17 30063[Note] InnoDB: Completed initialization of buffer pool49 2016-07-26 14:59:17 30063 [Note] InnoDB: Highest supported file format isBarracuda.50 2016-07-26 14:59:17 30063 [Note] InnoDB: 128rollback segment(s) are active.51 2016-07-26 14:59:17 30063 [Note] InnoDB: Waiting forpurge to start52 2016-07-26 14:59:17 30063 [Note] InnoDB: 5.6.22 started; log sequence number 1625977
53 2016-07-26 14:59:18 30063[Note] Binlog end54 2016-07-26 14:59:18 30063[Note] InnoDB: FTS optimize thread exiting.55 2016-07-26 14:59:18 30063[Note] InnoDB: Starting shutdown...56 2016-07-26 14:59:19 30063 [Note] InnoDB: Shutdown completed; log sequence number 1625987
57
58
59
60
61 A RANDOM PASSWORD HAS BEEN SET FOR THE MySQL root USER !
62 You will find that password in '/root/.mysql_secret'.63
64 You must change that password on your first connect,65 no other statement but 'SET PASSWORD'will be accepted.66 See the manual for the semantics of the 'password expired'flag.67
68 Also, the account forthe anonymous user has been removed.69
70 In addition, you can run:71
72 /usr/bin/mysql_secure_installation73
74 which will also give you the option of removing the test database.75 This is strongly recommended forproduction servers.76
77 See the manual formore instructions.78
79 Please report any problems at http://bugs.mysql.com/
80
81 The latest information about MySQL isavailable on the web at82
83 http://www.mysql.com
84
85 Support MySQL by buying support/licenses at http://shop.mysql.com
86
87 New default config file was created as /usr/my.cnf and88 will be used by defaultby the server when you start it.89 You may edit this file to change server settings
View Code
4.紧接着安装mysql-client
#rpm -ivh MySQL-client-5.6.22-1.el6.x86_64.rpm
由于安装好mysql-server之后没有办法在命令行下连接数据库,因此需要继续安装mysql-client,执行命令:
#rpm -ivh MySQL-client-5.6.22-1.el6.x86_64.rpm
等一会儿之后系统会提示安装成功,这个时候,执行下面一步
5. 连接数据库
mysql -u root -p 来进行连接mysql,连接的时候需要输入密码,密码就是之前生成的那个随机密码,输入即可成功!
进入到mysql控制台之后,执行:show databases;
发现系统提示需要先修改密码,于是:先exit系统,然后执行:mysqladmin -u root -p password 'new-passwd'
来修改密码,然后再次连接mysql,输入刚刚设置好的密码,然后继续执行show databases;命令,发现成功!
注意:如何查找安装成功后生成的随机密码
首先根据上面提示,随机生成一个root账户的密码,保存在: /root/.mysql_secret 这里;
执行:find / -name 寻找的文件
find / -name .mysql_secret 表示寻找随机密码存放在一个.mysql_secet文件中
vi /root/.mysql_secret 表示打开后缀名为.mysql_secret 的文件
获取到随机密码,如下图所示:
登陆账号mysql,以及更新密码已经验证成功如下图所示:
6. 安装的最后一步(还没完)
那么接下来就有个问题,是否还需要安装mysql-devel包?
尝试一下。。。。
执行:rpm -ivh MySQL-devel-5.6.20-1.el6.i686.rpm
提示安装成功,然后连接mysql,执行show databases; 依然可以。。。!
google一下:
MySQL-devel 貌似不是太必要~~
7.建好数据库后还要设置一下服务器访问权限
账号/密码 为 root,12345
如果你想root使用12345从任何主机连接到MySQL数据库服务器的话。使用如下授权权命令:
执行: GRANT ALL PRIVILEGES ON *.* TO 'root'@'%'IDENTIFIED BY '12345' WITH GRANT OPTION ;
执行: FLUSH PRIVILEGES
这种表示大功告成!
8.新创建用户以及赋予用户权限
首先登陆mysql
# mysql -u root -p
输入密码登陆成功后
例子:
1 mysql> CREATE USER 'root'@'localhost' IDENTIFIED BY '12345';2 Query OK, 0 rows affected (0.00sec)3
4 mysql> select host,user,password from mysql.user where user='root';5 +-----------+------+-------------------------------------------+
6 | host | user | password |
7 +-----------+------+-------------------------------------------+
8 | % | root| *88A48FD2A9FBD6C1F702D44BAC5CC74235964905 |
9 | localhost | root| *88A48FD2A9FBD6C1F702D44BAC5CC74235964905 |
10 +-----------+------+-------------------------------------------+
11 2 rows in set (0.00 sec)
View Code
再接着将赋予操作权限
赋予MySQL用户权限
一个新建的MySQL用户没有任何访问权限,这就意味着你不能在MySQL数据库中进行任何操作。你得赋予用户必要的权限。以下是一些可用的权限:
ALL: 所有可用的权限
CREATE: 创建库、表和索引
LOCK_TABLES: 锁定表
ALTER: 修改表
DELETE: 删除表
INSERT: 插入表或列
SELECT: 检索表或列的数据
CREATE_VIEW: 创建视图
SHOW_DATABASES: 列出数据库
DROP: 删除库、表和视图
运行以下命令赋予"myuser"用户特定权限。
mysql>GRANT ON .
以上命令中, 代表着用逗号分隔的权限列表。如果你想要将权限赋予任意数据库(或表),那么使用星号(*)来代替数据库(或表)的名字。
例如,为所有数据库/表赋予 ALL 权限:
mysql> GRANT ALL ON *.* TO 'yywl'@'localhost';
Query OK, 0 rows affected (0.01 sec)
参考网址:
http://www.linuxidc.com/Linux/2015-03/114803.htm
http://my.oschina.net/u/1156660/blog/343154
http://www.zixijiaoshi.com/html/sjk/mysql/2015/0210/1821.html
http://www.cnblogs.com/hb_cattle/archive/2011/10/16/2213825.html
本人遇到的错误总结:
1
ERROR2002(HY000):Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock'(2)
这是由于修改mysql服务的了socket文件mysql.sock位置,而导致无法通过mysql socket文件连接到mysql服务引起的,具体解决办法如下:
1、查看mysql服务的socket文件位置:
mysql socket文件的位置是在/etc/my.cnf中设置的,cat /etc/my.cnf内容如下:
1
2
3
4
[mysqld]
datadir=/storage/db/mysql
socket=/storage/db/mysql/mysql.sock
user=mysql
其中socket等于的路径就是socket文件的位置,我们只要修改my.cnf文件,告诉mysql,mysqldump,mysqladmin mysql服务的socket位置在哪里就可以。
参考网站 : http://www.aiezu.com/db/mysql_cant_connect_through_socket.html