#二进制安装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进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。