ITPub博客

首页 > 数据库 > MySQL > MySQL安装

MySQL安装

原创 MySQL 作者:sky850623 时间:2016-04-29 20:41:40 0 删除 编辑
1.查看mysql包是否安装
[root@localhost ~]# rpm -qa | grep mysql

2、添加mysql组和用户
[root@localhost ~]# groupadd mysql
[root@localhost ~]# useradd -r -g mysql -s /bin/false mysql

3、解压到/usr/local目录下
[root@localhost home]# tar -zxvf mysql-5.7.12-linux-glibc2.5-x86_64.tar.gz -C /usr/local/

4、名字太长创建一个软链接
[root@localhost home]# cd /usr/local/
[root@localhost local]# ln -s mysql-5.7.12-linux-glibc2.5-x86_64/ mysql

[root@localhost mysql]# ll
total 52
drwxr-xr-x  2 7161 wheel  4096 Mar 29 03:51 bin
-rw-r--r--  1 7161 wheel 17987 Mar 29 02:06 COPYING
drwxr-xr-x  2 7161 wheel  4096 Mar 29 03:51 docs
drwxr-xr-x  3 7161 wheel  4096 Mar 29 03:51 include
drwxr-xr-x  5 7161 wheel  4096 Mar 29 03:51 lib
drwxr-xr-x  4 7161 wheel  4096 Mar 29 03:51 man
-rw-r--r--  1 7161 wheel  2478 Mar 29 02:06 README
drwxr-xr-x 28 7161 wheel  4096 Mar 29 03:51 share
drwxr-xr-x  2 7161 wheel  4096 Mar 29 03:51 support-files

5、进入mysql文件夹,也就是mysql所在的目录,并更改所属的组和用户。
[root@localhost mysql]# chown -R mysql .
[root@localhost mysql]# chgrp -R mysql .
6、安装
[root@localhost mysql]# bin/mysqld --initialize --user=mysql
2016-04-29T10:45:11.121897Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2016-04-29T10:45:11.570719Z 0 [Warning] InnoDB: New log files created, LSN=45790
2016-04-29T10:45:11.681683Z 0 [Warning] InnoDB: Creating foreign key constraint system tables.
2016-04-29T10:45:11.887600Z 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: 73008434-0df7-11e6-91d9-000c29081134.
2016-04-29T10:45:11.891202Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened.
2016-04-29T10:45:11.892516Z 1 [Note] A temporary password is generated for root@localhost: Usqf4jeP6D,>

[root@localhost mysql]# bin/mysql_ssl_rsa_setup 
Generating a 2048 bit RSA private key
....+++
.................................................................................+++
writing new private key to 'ca-key.pem'
-----
Generating a 2048 bit RSA private key
................+++
........+++
writing new private key to 'server-key.pem'
-----
Generating a 2048 bit RSA private key
..............................................................................................................................................+++
....................+++
writing new private key to 'client-key.pem'
-----

7、将mysql/目录下除了data/目录的所有文件,改回root用户所有,mysql用户只需作为mysql/data/目录下所有文件的所有者。
[root@localhost mysql]# chown -R root .
[root@localhost mysql]# chown -R mysql data
[root@localhost mysql]# ll
total 56
drwxr-xr-x  2 root  mysql  4096 Mar 29 03:51 bin
-rw-r--r--  1 root  mysql 17987 Mar 29 02:06 COPYING
drwxr-x---  5 mysql mysql  4096 Apr 29 18:47 data
drwxr-xr-x  2 root  mysql  4096 Mar 29 03:51 docs
drwxr-xr-x  3 root  mysql  4096 Mar 29 03:51 include
drwxr-xr-x  5 root  mysql  4096 Mar 29 03:51 lib
drwxr-xr-x  4 root  mysql  4096 Mar 29 03:51 man
-rw-r--r--  1 root  mysql  2478 Mar 29 02:06 README
drwxr-xr-x 28 root  mysql  4096 Mar 29 03:51 share
drwxr-xr-x  2 root  mysql  4096 Mar 29 03:51 support-files

8、添加服务
[root@localhost mysql]# cp support-files/mysql.server /etc/init.d/mysqld
[root@localhost mysql]# service mysqld start
Starting MySQL..[  OK  ]
9、配置环境变量
将mysql的bin目录加入PATH环境变量
vi /etc/profile
PATH=$PATH:/usr/local/mysql/bin
export PATH

问题解决:
[root@localhost init.d]# mysql -uroot
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)

[root@localhost mysql]# bin/mysqld_safe --user=mysql --skip-grant-tables &
[root@localhost mysql]# mysql
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.7.12 MySQL Community Server (GPL)

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> 

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 authentication_string=password('123qwe') where user='root';
Query OK, 1 row affected, 1 warning (0.01 sec)
Rows matched: 1  Changed: 1  Warnings: 1

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

mysql> quit
Bye


[root@localhost mysql]# 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.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> show databases;
ERROR 1820 (HY000): You must reset your password using ALTER USER statement before executing this statement.
mysql> alter user 'root'@'localhost' identified by '123';
Query OK, 0 rows affected (0.00 sec)

10、开机自启动
[root@localhost mysql]# chkconfig --add mysqld
[root@localhost mysql]# chkconfig --list mysqld
mysqld          0:off   1:off   2:on    3:on    4:on    5:on    6:off


来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/26937943/viewspace-2090862/,如需转载,请注明出处,否则将追究法律责任。

上一篇: 应用
下一篇: python安装
请登录后发表评论 登录
全部评论

注册时间:2013-05-30

  • 博文量
    154
  • 访问量
    495027