《MysqL必读centos下安装MysqL服务器的方法》要点:
本文介绍了MysqL必读centos下安装MysqL服务器的方法,希望对您有用。如果有疑问,可以联系我们。
下面把我安装过程中遇到的问题给传上来,
首先rpm格式安装就不多说了,主要是MysqL的配置文件在:/etc/my.cnf这里,需要修改:
代码如下:
[MysqLd]
datadir=/var/lib/MysqL
socket=/var/lib/MysqL/MysqL.sock
# Default to using old password format for compatibility with MysqL 3.x
# clIEnts (those using the MysqLclIEnt10 compatibility package).
old_passwords=1 ← 找到这一行,在这一行的下面添加新的规则,让MysqL的默认编码为UTF-8
default-character-set = utf8 ← 添加这一行
然后在配置文件的文尾填加如下语句:
[MysqL]
default-character-set = utf8
然后我就直接启动MysqL了,还以为是Ubuntu的那样呢,安装后自动启动,可是centos不一样,服务没有启动所以就抱错了.
代码如下:
[root@fsailing1 init.d]# MysqL -u root
ERROR 2002 (HY000): Can't connect to local MysqL server through socket '/var/run/MysqLd/MysqLd.sock' (2)
这个错误之前遇到过,就是因为错误或者其他的什么原因,MysqL服务器没有启动造成的.
接着启动MysqL服务:
代码如下:
root@fsailing1 init.d]# /etc/rc.d/init.d/MysqLd start
启动 MysqL: [确定]
[root@fsailing1 init.d]# ps -ef |grep MysqL
root 1949 1 0 22:21 pts/1 00:00:00 /bin/sh /usr/bin/MysqLd_safe --datadir=/var/lib/MysqL --socket=/var/lib/MysqL/MysqL.sock --log-error=/var/log/MysqLd.log --pID-file=/var/run/MysqLd/MysqLd.pID --user=MysqL
MysqL 2002 1949 1 22:21 pts/1 00:00:00 /usr/libexec/MysqLd --basedir=/usr --datadir=/var/lib/MysqL --user=MysqL --pID-file=/var/run/MysqLd/MysqLd.pID --skip-external-locking --socket=/var/lib/MysqL/MysqL.sock
root 2020 1101 0 22:21 pts/1 00:00:00 grep MysqL
启动方式有很多种:service方式service MysqLd start 和安全方式:/usr/bin/MysqLd_safe &
通过启动服务的后缀我们可以清楚的看到,数据库放在那里,错误日志在哪里,
完事之后,要看看字符集的问题(这个问题至今我还没有搞清楚呢).是否匹配:
代码如下:
MysqL> show variables like 'character%';
+--------------------------+----------------------------+
| Variable_name | Value |
+--------------------------+----------------------------+
| character_set_clIEnt | latin1 |
| character_set_connection | latin1 |
| character_set_database | utf8 |
| character_set_filesystem | binary |
| character_set_results | latin1 |
| character_set_server | utf8 |
| character_set_system | utf8 |
| character_sets_dir | /usr/share/MysqL/charsets/ |
+--------------------------+----------------------------+
8 rows in set (0.00 sec)
这种情况是不行的,我们只是改变了服务器的字符集,没有改变客户端的字符集.
修改my.cnf文件后,重启MysqL服务器后得知:
代码如下:
MysqL> show variables like 'character%';
+--------------------------+----------------------------+
| Variable_name | Value |
+--------------------------+----------------------------+
| character_set_clIEnt | utf8 |
| character_set_connection | utf8 |
| character_set_database | utf8 |
| character_set_filesystem | binary |
| character_set_results | utf8 |
| character_set_server | utf8 |
| character_set_system | utf8 |
| character_sets_dir | /usr/share/MysqL/charsets/ |
+--------------------------+----------------------------+
8 rows in set (0.00 sec)
这样就算是完成了,字符集的配置了.然后呢就是密码和授权问题了.
查看用户密码:
代码如下:
MysqL> select host,user,password from user;
+-----------+------+----------+
| host | user | password |
+-----------+------+----------+
| localhost | root | |
| fsailing1 | root | |
| 127.0.0.1 | root | |
| localhost | | |
| fsailing1 | | |
+-----------+------+----------+
5 rows in set (0.00 sec)
这里用户和密码有的是空的,怪不得不需要任何验证都能够登录到服务器上去,这是很不安全的.所以要删除这些不安全的用户
代码如下:
MysqL> delete from user where user='';
query OK,2 rows affected (0.00 sec)
MysqL> select host,password from user;
+-----------+------+----------+
| host | user | password |
+-----------+------+----------+
| localhost | root | |
| fsailing1 | root | |
| 127.0.0.1 | root | |
+-----------+------+----------+
3 rows in set (0.00 sec)
然后是设置现有的用户密码:这里可以update,set都行.
代码如下:
MysqL> update user set password='123' where host='localhost';
query OK,1 row affected (0.00 sec)
Rows matched: 1 Changed: 1 Warnings: 0
MysqL> select host,password from user;
+-----------+------+----------+
| host | user | password |
+-----------+------+----------+
| localhost | root | 123 |
| fsailing1 | root | |
| 127.0.0.1 | root | |
+-----------+------+----------+
3 rows in set (0.00 sec)
这里我一看傻眼了,没有经过md5码加密呢,算了这里还只能用set进行设置密码呢.
代码如下:
MysqL> set password for root@localhost=password('123');
query OK,0 rows affected (0.00 sec)
MysqL> select host,password from user;
+-----------+------+------------------+
| host | user | password |
+-----------+------+------------------+
| localhost | root | 773359240eb9a1d9 |
| fsailing1 | root | |
| 127.0.0.1 | root | |
+-----------+------+------------------+
3 rows in set (0.00 sec)
到这里该做的基本上就算是完事了.
总结
以上是内存溢出为你收集整理的Mysql必读centos下安装mysql服务器的方法全部内容,希望文章能够帮你解决Mysql必读centos下安装mysql服务器的方法所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)