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/100: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/100: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/100: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, user ,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, user ,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, user ,password from user
+-----------+------+------------------+
| host | user | password |
+-----------+------+------------------+
| localhost | root | 773359240eb9a1d9 |
| fsailing1 | root | |
| 127.0.0.1 | root | |
+-----------+------+------------------+
3 rows in set (0.00 sec)
到这里该做的基本上就算是完事了。
---------------------------------我只是搬运工
RedHat Linux (Fedora Core/Cent OS)
1.启动:/etc/init.d/mysqld start
2.停止:/etc/init.d/mysqld stop
3.重启:/etc/init.d/mysqld restart
Debian / Ubuntu Linux
1.启动:/etc/init.d/mysql start
2.停止:/etc/init.d/mysql stop
3.重启:/etc/init.d/mysql restart
Windows
1.点击“开始”->“运行”(快捷键Win+R)
2.启动:输入 net stop mysql
3.停止:输入 net start mysql
提示
Redhat Linux 也支持service command,
启动:# service mysqld start
停止:# service mysqld stop
重启:# service mysqld restart
Windows下不能直接重启(restart),只能先停止,再启动。
阿里云安装mysql
有话好说,以下是CentOS Linux 5的配置经验:添加mysql帐号
groupadd mysql
useradd -r -g mysql mysql
编译必需先安装
cmake-2.8.4 和 bison-2.4.3
安装成功后解压mysql-5.5.15.tar.gz:
在源码根目录打开终端输入以下配置参数并回车
cmake -DCMAKE_INSTALL_PREFIX=/etc/mysql \
-DMYSQL_UNIX_ADDR=/etc/mysql/mysql.sock \
-DDEFAULT_CHARSET=utf8 \
-DDEFAULT_COLLATION=utf8_general_ci \
-DWITH_EXTRA_CHARSETS:STRING=utf8,gbk \
-DWITH_MYISAM_STORAGE_ENGINE=1 \
-DWITH_INNOBASE_STORAGE_ENGINE=1 \
-DWITH_MEMORY_STORAGE_ENGINE=1 \
-DWITH_READLINE=1 \
-DENABLED_LOCAL_INFILE=1 \
-DMYSQL_DATADIR=/var/mysql/data \
-DMYSQL_USER=mysql
成功执行以下命令后在最后会见到 (/root/Desktop/是你的源码目录,视你的情况定)
-- Build files have been written to: /root/Desktop/mysql-5.5.15
运行make安装:
make
make install
以下步骤就不一一解说了:
cd /mysql/mysql
chown -R mysql:mysql .
scripts/mysql_install_db --user=mysql
chown -R root .
chown -R mysql data
cp ./support-files/my-small.cnf ./my.cnf
cp support-files/mysql.server mysqlchmod +x mysql
chown -R mysql:root .
./mysql start
./bin/mysqladmin -u root -p 123456
添加开机启动服务
chkconfig --add mysql
chkconfig mysql on
service mysql start
顺利的话到这里完成了,祝你成功。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)