您好,登錄后才能下訂單哦!
#二進制安裝mysql,直接解壓初始化數據庫就可以了
1.創建用戶和組
[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/
#獨立安裝數據庫到此結束。
[root@Lnmp tools]# mkdir -p /application/mysql/data/
[root@Lnmp tools]#chown -R mysql.mysql /application/mysql/data
3.初始化數據庫
[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 #指定配置文件
#如果不指定則,啟動時出現:
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
出現下面錯誤:
#-bash:mysql:command not found
mysql 對應的路徑不在path目錄下面
使用全路徑進入mysql:
/application/mysql/bin/mysql
或者在文件最后加上:
vi /etc/profile
PATH="/application/mysql/bin/:$PATH"
#. /etc/profile #使之生效
mysql>
#設置密碼,不要在mysql> 下面設置密碼,在#后面設置密碼
/application/mysql/bin/mysqladmin -u root password 'passwd123'
#重新登錄
mysql -u root -p
passwd123
5.數據優化:
select version(); #查看數據庫版本
select user(); #查看當前的用戶
mysql> show databases; #查看數據庫
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| test |
+--------------------+
mysql>drop database test; #安全設置,刪除沒有用的數據庫
#最終優化為:
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;
#最終優化為:
mysql> select user,host from mysql.user;
+------+-----------+
| user | host |
+------+-----------+
| root | 127.0.0.1 |
| root | localhost |
+------+-----------+
最后:
flush privileges;
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。