这篇文章主要为大家详细介绍了centos下安装MySQL服务器的方法,具有一定的参考价值,可以用来参考一下。
感兴趣的小伙伴,下面一起跟随四海网的小编小韵来看看吧!
项目需要就在现有的服务器上面重新安装了个mysql服务器,还挺费劲儿呢,因为之前都是在我的笔记本上面试验的,它的系统是Ubuntu的,什么路径啊,启动方式啊。都不一样所以这次还是让我纠结了一把:代码如下:
[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
代码如下:
[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)
代码如下:
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
代码如下:
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)
代码如下:
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, user ,password from user;
+-----------+------+----------+
| host | user | password |
+-----------+------+----------+
| localhost | root | |
| fsailing1 | root | |
| 127.0.0.1 | root | |
+-----------+------+----------+
3 rows in set (0.00 sec)
代码如下:
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, user ,password from user;
+-----------+------+----------+
| host | user | password |
+-----------+------+----------+
| localhost | root | 123 |
| fsailing1 | root | |
| 127.0.0.1 | root | |
+-----------+------+----------+
3 rows in set (0.00 sec)
代码如下:
mysql> set password for root@localhost=password('123');
Query OK, 0 rows affected (0.00 sec)
mysql> select host, user ,password from user;
+-----------+------+------------------+
| host | user | password |
+-----------+------+------------------+
| localhost | root | 773359240eb9a1d9 |
| fsailing1 | root | |
| 127.0.0.1 | root | |
+-----------+------+------------------+
3 rows in set (0.00 sec)
本文来自:http://www.q1010.com/177/9834-0.html
注:关于centos下安装MySQL服务器的方法的内容就先介绍到这里,更多相关文章的可以留意四海网的其他信息。
关键词:MYSQL
四海网收集整理一些常用的php代码,JS代码,数据库mysql等技术文章。