linux下mysql的简单配置

本文详细介绍了在Linux环境下配置MySQL数据库的过程,包括设置字符编码、启动及开机自启、创建root管理员账号、解决远程访问问题等关键步骤,并提供了具体的命令操作和注意事项,确保数据库稳定高效运行。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

1、设置字符编码 输入命令: [root@localhost ~]# vi /etc/my.cnf 最后一行加入:default-character-set=utf8,保存! 2、启动mysql服务: 输入命令: [root@localhost ~]# service mysqld start 返回一下信息则表示已经启动成功 Initializing MySQL database: Installing MySQL system tables... OK Filling help tables... OK

To start mysqld at boot time you have to copy support-files/mysql.server to the right place for your system

PLEASE REMEMBER TO SET A PASSWORD FOR THE MySQL root USER ! To do so, start the server, then issue the following commands:

/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_installation

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.

See the manual for more instructions.

You can start the MySQL daemon with: cd /usr ; /usr/bin/mysqld_safe &

You can test the MySQL daemon with mysql-test-run.pl cd /usr/mysql-test ; perl mysql-test-run.pl

Please report any problems with the /usr/bin/mysqlbug script!

                                                       [  OK  ]

Starting mysqld: [ OK ]

3、设置开机启动: 输入命令: [root@localhost ~]# chkconfig --add mysqld [root@localhost ~]# chkconfig mysqld on

4、查看开机启动设置是否成功 输入命令: [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

5、创建root管理员: 输入命令:(设置用户名为root,密码为123456) [root@localhost ~]# mysqladmin -u root password 123456

6、登录数据库: 输入命令: [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>

7、如果是你的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;

恭喜你,到此为止,你再远程登陆就可以登陆成功了。

转载于:https://my.oschina.net/u/273709/blog/410726

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值