3.centos 命令行 之 5.7mysql安装(tar.gz 解压版,root用户)

1.首先通过wget进行mysql5.7的下载:

进入如下网页(https://dev.mysql.com/downloads/file/?id=467556):

174847_1sqY_2918544.png

然后获取下载的实际地址:

180452_ABiN_2918544.png

然后通过putty进入远程服务器,cd进入到需要放置的目录,比如:

cd /usr/local/

然后:

wget  https://cdn.mysql.com//Downloads/MySQL-5.7/mysql-5.7.17-linux-glibc2.5-x86_64.tar.gz

六百多兆慢慢下,下载完成后解压,

tar xvf mysql-5.7.17-linux-glibc2.5-x86_64.tar.gz

解压之后移动到 /usr/local/mysql下,因为已经在/usr/local/目录下就是在local目录下更改名称为mysql就好了:

命令:mv mysql-5.7.17-linux-glibc2.5-x86_64 mysql

然后在/usr/local/进行如下操作:

添加用户组:groupadd mysql

添加用户:useradd -r -g mysql mysql

然后增加权限:

chown -R mysql mysql/

chgrp -R mysql mysql/

进入mysql目录:创建 data目录:

mkdir data

然后执行:

bin/mysql_install_db --user=mysql --basedir=/usr/local/mysql/ --datadir=/usr/local/mysql/data/

注意如果改变默认安装路径,则需要(严格按照以上步骤,则无需关注):

1)/etc/my.cnf、/etc/init.d/mysqld中修改
basedir='/apps/mysql'
datadir='/apps/mysql/data'
2)创建ln
mkdir -p /usr/local/mysql/bin
ln -s /apps/mysql/bin/mysqld /usr/local/mysql/bin/mysqld

  然后执行:cp -a ./support-files/my-default.cnf /etc/my.cnf

输入 y 确认覆盖(如果有)

执行: cp -a ./support-files/mysql.server  /etc/init.d/mysqld

进入bin目录:cd bin/  然后执行如下命令,  后台启动mysql

 ./mysqld_safe --user=mysql &

参看: http://www.educity.cn/wenda/403269.html

启动:

/etc/init.d/mysqld restart

设置开机启动:

chkconfig --level 35 mysqld on

初始化密码

cat /root/.mysql_secret 

 

然后进入mysql:

./mysql -u root -p

输入图片里红框写的密码,执行sql语句如下:

SET PASSWORD = PASSWORD('123456');

 flush privileges;

 添加远程访问权限,进入 mysql 库:

use mysql; 

update user set host = '%' where user = 'root';

完成,退出mysql,执行下列命令是配置生效。

/etc/init.d/mysqld restart

然后,使用自己的电脑比如navicat软件链接数据库进行测试。

 

 

执行记录如下:

[root@VM_187_61_centos tomcat]# cd ..
[root@VM_187_61_centos installjdk]# cd mysql57/
[root@VM_187_61_centos mysql57]# ls
COPYING  README  bin  docs  include  lib  man  share  support-files
[root@VM_187_61_centos mysql57]# cd /usr/
[root@VM_187_61_centos usr]# cd tmp/
[root@VM_187_61_centos tmp]# cd l
-bash: cd: l: No such file or directory
[root@VM_187_61_centos tmp]# cd local/
-bash: cd: local/: No such file or directory
[root@VM_187_61_centos tmp]# ls
[root@VM_187_61_centos tmp]# cd ..
[root@VM_187_61_centos usr]# ls
bin  games    java  lib64    local  share  tmp
etc  include  lib   libexec  sbin   src
[root@VM_187_61_centos usr]# cd local/
[root@VM_187_61_centos local]# ls
bin  games    lib    libexec  qcloud  sbin   src
etc  include  lib64  mysql    sa      share  tomcat
[root@VM_187_61_centos local]# cd mysql/
[root@VM_187_61_centos mysql]# ls
COPYING  README  bin  docs  include  lib  man  share  support-files
[root@VM_187_61_centos mysql]# clear
[root@VM_187_61_centos mysql]# pwd
/usr/local/mysql
[root@VM_187_61_centos mysql]# mkdir data
[root@VM_187_61_centos mysql]# ls
COPYING  README  bin  data  docs  include  lib  man  share  support-files
[root@VM_187_61_centos mysql]# groupadd mysql
[root@VM_187_61_centos mysql]# useradd -r -g mysql mysql
[root@VM_187_61_centos mysql]# chown -R mysql:mysql ./
[root@VM_187_61_centos mysql]# ./scripts/mysql_install_db --user=mysql
-bash: ./scripts/mysql_install_db: No such file or directory
[root@VM_187_61_centos mysql]# ls
COPYING  README  bin  data  docs  include  lib  man  share  support-files
[root@VM_187_61_centos mysql]# cd ..
[root@VM_187_61_centos local]# chgrp -R mysql mysql/
[root@VM_187_61_centos local]# cd mysql
[root@VM_187_61_centos mysql]# bin/mysql_install_db --user=mysql --basedir=/usr/local/mysql/ --datadir=/usr/local/mysql/data/
2017-04-11 17:36:23 [WARNING] mysql_install_db is deprecated. Please consider switching to mysqld --initialize
2017-04-11 17:36:39 [WARNING] The bootstrap log isn't empty:
2017-04-11 17:36:39 [WARNING] 2017-04-11T09:36:23.845893Z 0 [Warning] --bootstrap is deprecated. Please consider using --initialize instead

[root@VM_187_61_centos mysql]# cp -a ./support-files/my-default.cnf /etc/my.cnf
cp: overwrite '/etc/my.cnf'? y
[root@VM_187_61_centos mysql]#  cp -a ./support-files/mysql.server  /etc/init.d/mysqld
[root@VM_187_61_centos mysql]# cd bin/
[root@VM_187_61_centos bin]# ./mysqld_safe --user=mysql &
[1] 5641
[root@VM_187_61_centos bin]# [1] 29322017-04-11T09:37:45.323188Z mysqld_safe Logging to '/usr/local/mysql/data/VM_187_61_centos.err'.
Logging to '/usr/local/mysql/data/VM_187_61_centos.err'.
2017-04-11T09:37:45.460829Z mysqld_safe Starting mysqld daemon with databases from /usr/local/mysql/data

-bash: [1]: command not found
[root@VM_187_61_centos bin]# ./mysqld_safe --user=mysql & [1] 2932
[2] 5820
-bash: [1]: command not found
[root@VM_187_61_centos bin]# Usage: grep [OPTION]... PATTERN [FILE]...
Try 'grep --help' for more information.
grep: write error: Broken pipe
2017-04-11T09:38:13.344414Z mysqld_safe Logging to '/usr/local/mysql/data/VM_187_61_centos.err'.
2017-04-11T09:38:13.346134Z mysqld_safe Logging to '/usr/local/mysql/data/VM_187_61_centos.err'.
2017-04-11T09:38:13.360057Z mysqld_safe A mysqld process already exists
^C
[2]+  Exit 1                  ./mysqld_safe --user=mysql
[root@VM_187_61_centos bin]#
[root@VM_187_61_centos bin]#
[root@VM_187_61_centos bin]#
[root@VM_187_61_centos bin]# /etc/init.d/mysqld restart
Shutting down MySQL..2017-04-11T09:38:48.084004Z mysqld_safe mysqld from pid file /usr/local/mysql/data/VM_187_61_centos.pid ended
 SUCCESS!
Starting MySQL. SUCCESS!
[1]+  Done                    ./mysqld_safe --user=mysql
[root@VM_187_61_centos bin]# chkconfig --level 35 mysqld on
[root@VM_187_61_centos bin]# cat /root/.mysql_secret
# Password set for user 'root@localhost' at 2017-04-11 17:36:23
NwWDrbgr)yhd
[root@VM_187_61_centos bin]# ./mysql -u root -p
Enter password:
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES)
[root@VM_187_61_centos bin]# ./mysql -u root -p
Enter password:
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES)
[root@VM_187_61_centos bin]# ./mysql -u root -p
Enter password:
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 5
Server version: 5.7.17

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('951357qaz');
Query OK, 0 rows affected, 1 warning (0.01 sec)

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

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 |
+-----------+-----------+
2 rows in set (0.00 sec)

mysql> /etc/init.d/mysqld restart
    -> ;
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '/etc/init.d/mysqld restart' at line 1
mysql> exit
Bye
[root@VM_187_61_centos bin]# /etc/init.d/mysqld restart
Shutting down MySQL.. SUCCESS!
Starting MySQL. SUCCESS!
[root@VM_187_61_centos bin]# ./mysql -u root -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)

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;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| performance_schema |
| sys                |
+--------------------+
4 rows in set (0.00 sec)

mysql> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| performance_schema |
| sys                |
| test               |
+--------------------+
5 rows in set (0.00 sec)

mysql> exit
Bye
[root@VM_187_61_centos bin]#

 

转载于:https://my.oschina.net/viakiba/blog/877122

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值