溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點(diǎn)擊 登錄注冊 即表示同意《億速云用戶服務(wù)條款》

mysql 數(shù)據(jù)庫的安裝之 二 二進(jìn)制安裝

發(fā)布時間:2020-05-18 13:20:36 來源:網(wǎng)絡(luò) 閱讀:1045 作者:ahtornado 欄目:數(shù)據(jù)庫

#二進(jìn)制安裝mysql,直接解壓初始化數(shù)據(jù)庫就可以了

1.創(chuàng)建用戶和組

[root@Lnmp tools]#useradd mysql -s /sbin/nologin/ -M

2.解壓安裝包

[root@Lnmp tools]#tar xf mysql-5.5.32-linux2.6-x86_64.tar.gz 


[root@Lnmp tools]#mv mysql-5.5.32-linux2.6-x86_64 mysql

[root@Lnmp tools]#mv mysql /application/ 

#獨(dú)立安裝數(shù)據(jù)庫到此結(jié)束。

[root@Lnmp tools]# mkdir -p /application/mysql/data/


[root@Lnmp tools]#chown -R mysql.mysql /application/mysql/data


3.初始化數(shù)據(jù)庫

[root@Lnmp tools]# cd /application/mysql/

[root@Lnmp mysql]# ./scripts/mysql_install_db --user=mysql --basedir=/application/mysql/ --datadir=/application/mysql/data/

WARNING: The host 'Lnmp' could not be looked up with resolveip.

This probably means that your libc libraries are not 100 % compatible

with this binary MySQL version. The MySQL daemon, mysqld, should work

normally with the exception that host name resolving will not work.

This means that you should use IP addresses instead of hostnames

when specifying MySQL privileges !

Installing MySQL system tables...

OK

Filling help tables...

OK


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


[root@Lnmp mysql]#cp support-files/my-small.cnf /etc/my.cnf  #指定配置文件


#如果不指定則,啟動時出現(xiàn):

ERROR 2002 (HY000):Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock/(2)


4.啟動Mysql:

[root@Lnmp mysql]# /etc/init.d/mysqld start 

/etc/init.d/mysqld: line 276: cd: /usr/local/mysql: No such file or directory

Starting MySQL ERROR! Couldn't find MySQL server (/usr/local/mysql/bin/mysqld_safe)

如果不成功則修改下面:

[root@Lnmp mysql]# vi /etc/init.d/mysqld  +46

basedir=/application/mysql

datadir=/application/mysql/data


[root@Lnmp mysql]# /etc/init.d/mysqld start

Starting MySQL.. SUCCESS! 


#登錄

#mysql

出現(xiàn)下面錯誤:

#-bash:mysql:command not found

mysql 對應(yīng)的路徑不在path目錄下面

使用全路徑進(jìn)入mysql:

/application/mysql/bin/mysql

或者在文件最后加上:

vi /etc/profile

PATH="/application/mysql/bin/:$PATH"

#. /etc/profile   #使之生效

mysql>


#設(shè)置密碼,不要在mysql>  下面設(shè)置密碼,在#后面設(shè)置密碼

/application/mysql/bin/mysqladmin -u  root password 'passwd123'

#重新登錄


mysql -u root -p

passwd123


5.數(shù)據(jù)優(yōu)化:

select version();         #查看數(shù)據(jù)庫版本

select user();            #查看當(dāng)前的用戶

mysql> show databases;    #查看數(shù)據(jù)庫

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

| Database           |

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

| information_schema |

| mysql              |

| performance_schema |

| test               |

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


mysql>drop database test; #安全設(shè)置,刪除沒有用的數(shù)據(jù)庫

#最終優(yōu)化為:

mysql> show databases;

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

| Database           |

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

| information_schema |

| mysql              |

| performance_schema |

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

mysql> select user,host from mysql.user;  #查詢表中的用戶

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

| user | host      |

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

| root | 127.0.0.1 |

| root | ::1       |

|      | Lnmp      |

| root | Lnmp      |

|      | localhost |

| root | localhost |

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

mysql>delete from mysql.user where(host="Lnmp");

mysql>delete from mysql.user where(host="::1");

mysql> drop user ""@localhost;

#最終優(yōu)化為:

mysql> select user,host from mysql.user;

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

| user | host      |

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

| root | 127.0.0.1 |

| root | localhost |

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

最后:

flush privileges;


向AI問一下細(xì)節(jié)

免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。

AI