一、设置字符编码 输入命令: [root@localhost ~]# vi /etc/my.cnf 最后一行加入:default-character-set=utf8,保存! 二、启动mysql服务: 输入命令: [root@localhost ~]# service mysqld start 返回一下信息则表示已经启动成功 Initializing MySQL database: Installing MySQL system tables... OK Filling help tables... OKmysql
To start mysqld at boot time you have to copy support-files/mysql.server to the right place for your systemlinux
PLEASE REMEMBER TO SET A PASSWORD FOR THE MySQL root USER ! To do so, start the server, then issue the following commands:sql
/usr/bin/mysqladmin -u root password 'new-password' /usr/bin/mysqladmin -u root -h localhost.localdomain password 'new-password'数据库
Alternatively you can run: /usr/bin/mysql_secure_installationdom
which will also give you the option of removing the test databases and anonymous user created by default. This is strongly recommended for production servers.tcp
See the manual for more instructions.编码
You can start the MySQL daemon with: cd /usr ; /usr/bin/mysqld_safe &rest
You can test the MySQL daemon with mysql-test-run.pl cd /usr/mysql-test ; perl mysql-test-run.plcode
Please report any problems with the /usr/bin/mysqlbug script!server
[ OK ]
Starting mysqld: [ OK ]
三、设置开机启动: 输入命令: [root@localhost ~]# chkconfig --add mysqld [root@localhost ~]# chkconfig mysqld on
四、查看开机启动设置是否成功 输入命令: [root@localhost ~]# chkconfig --list | grep mysql* mysqld 返回一下信息则表示已经设置成功 grep: mysqld: No such file or directory [root@localhost ~]# chkconfig --list | grep mysql* mysqld 0:off 1:off 2:on 3:on 4:on 5:on 6:off
五、建立root管理员: 输入命令:(设置用户名为root,密码为123456) [root@localhost ~]# mysqladmin -u root password 123456
六、登陆数据库: 输入命令: [root@localhost ~]# mysql -u root -p Enter password: 返回一下信息则表示登录成功 Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 3 Server version: 5.1.73 Source distribution
Copyright (c) 2000, 2013, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its affiliates. Other names may be trademarks of their respective owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql>
七、若是是你的mysql数据库是虚拟机linux端安装的,可能会遇到远程访问不了的问题,解决方案以下: (1)修改防火墙,开启3306端口。 输入命令: [root@localhost ~]# vi /etc/sysconfig/iptables 添加一行: -A INPUT -m state --state NEW -m tcp -p tcp --dport 3306 -j ACCEPT (2)重启服务 输入命令: [root@localhost ~]# service iptables restart 返回信息: iptables: Flushing firewall rules: [ OK ] iptables: Setting chains to policy ACCEPT: filter [ OK ] iptables: Unloading modules: [ OK ] iptables: Applying firewall rules: [ OK ] (3)受权用户从远程登陆 具体步骤:登录到mysql 首先 use mysql; mysql> update user set host='%' where user = 'root'; 返回信息: ERROR 1062 (23000): Duplicate entry '%-root' for key 'PRIMARY' 而后查看了下数据库的host信息以下: mysql> select host from user where user = 'root'; +-----------------------+ | host | +-----------------------+ | % | | 127.0.0.1 | | localhost.localdomain | +-----------------------+ 3 rows in set (0.00 sec) host已经有了%这个值,因此直接运行命令: mysql>flush privileges;
恭喜你,到此为止,你再远程登录就能够登录成功了。