基於Redhat7.2的mysql搭建

    這篇我們來裝一下MySQL~

    友情鏈接:http://downloads.mysql.com/archives/mysql-5.7/mysql-5.7.14.tar.gz

    (我用的版本是5.6的啦,大同小異~)

1、指定安裝包的位置

[root@localhost~]# mv mysql-5.6.33-linux-glibc2.5-x86_64.tar.gz /usr/local/

2、解壓

[root@localhost~]# tar zxvf mysql-5.6.33-linux-glibc2.5-x86_64.tar.gz

3、創建mysql用戶,事先存在的話可以先刪掉

[root@localhost mysql]# id mysql

uid=27(mysql) gid=27(mysql) groups=27(mysql)

[root@localhost mysql]# userdel -r mysql

[root@localhost mysql]# groupadd mysql

[root@localhost mysql]# useradd -g mysql mysql

[root@localhost mysql]# id mysql

uid=1002(mysql) gid=1002(mysql) groups=1002(mysql)

4、改變當前文件的所屬用戶所屬組

[root@localhost mysql]# chown -R mysql:mysql ./

5、執行安裝

[root@localhost mysql]# ./scripts/mysql_install_db --user=mysql

6、更改權限(使用/date/mysql存放數據)

[root@localhost mysql]# chown -R root:root ./

[root@localhost mysql]# chown -R mysql:mysql /data/mysql

[root@localhost mysql]# mkdir /data/mysql -p

[root@localhost mysql]# chown -R mysql:mysql /data/mysql

7、此時更改root的密碼會發生錯誤

[root@localhost mysql]# ./bin/mysqladmin -u root password 'root'

./bin/mysqladmin: connect to server at 'localhost' failed

error: 'Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2)'

Check that mysqld is running and that the socket: '/tmp/mysql.sock' exists!

8、啓動數據庫

[root@localhost mysql]# ./support-files/mysql.server start

Starting MySQL. SUCCESS!

9、更改root的連接密碼

[root@localhost mysql]# ./bin/mysqladmin -u root -h localhost.localdomain password 'root'

Warning: Using a password on the command line interface can be insecure.

9、連接數據庫

[root@localhost mysql]# ./bin/mysql -h 127.0.0.1 -uroot -proot

Warning: Using a password on the command line interface can be insecure.

Welcome to the MySQL monitor. Commands end with ; or \g.

Your MySQL connection id is 2

Server version: 5.6.33 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> exit

Bye

10、添加mysqld服務

[root@localhost mysql]# cp support-files/mysql.server /etc/init.d/mysqld

[root@localhost mysql]# chkconfig --add mysqld

[root@localhost mysql]# chkconfig mysqld on

[root@localhost mysql]# service mysqld restart

Shutting down MySQL.. SUCCESS!

Starting MySQL. SUCCESS!

[root@localhost mysql]# service mysqld status

SUCCESS! MySQL running (58914)

11、查看mysql相關進程

[root@localhost mysql]# ps -ef | grep mysql

root 58749 1 0 23:23 pts/0 00:00:00 /bin/sh /usr/local/mysql/bin/mysqld_safe --datadir=/var/lib/mysql --pid-file=/var/lib/mysql/localhost.localdomain.pid

mysql 58914 58749 1 23:23 pts/0 00:00:00 /usr/local/mysql/bin/mysqld --basedir=/usr/local/mysql --datadir=/var/lib/mysql --plugin-dir=/usr/local/mysql/lib/plugin --user=mysql --log-error=/var/log/mariadb/mariadb.log --pid-file=/var/lib/mysql/localhost.localdomain.pid --socket=/var/lib/mysql/mysql.sock

root 58974 12939 0 23:23 pts/0 00:00:00 grep --color=auto mysql

12、查看mysql端口號

[root@localhost mysql]# netstat -tupln|grep mysql

tcp6 0 0 :::3306 :::* LISTEN 58914/mysqd

13、登陸數據庫

[root@localhost php]# mysql -uroot -proot

Welcome to the MariaDB monitor. Commands end with ; or \g.

Your MySQL connection id is 1

Server version: 5.6.33 MySQL Community Server (GPL)

 

Copyright (c) 2000, 2015, Oracle, MariaDB Corporation Ab and others.

 

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

14、查看數據庫

MySQL [(none)]> show databases;

+--------------------+

| Database |

+--------------------+

| information_schema |

| mysql |

| performance_schema |

| test |

+--------------------+

4 rows in set (0.11 sec)

    完成啦~

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章