Home > Database > Mysql Tutorial > Linux下MySQL的一些操作

Linux下MySQL的一些操作

WBOY
Release: 2016-06-07 17:08:08
Original
1028 people have browsed it

1、Linux下启动Mysql的命令:/etc/init.d/mysql start2、关闭Mysql的命令:/etc/init.d/mysql shutdown3、重启Mysql的命令:/etc/i

1、Linux下启动Mysql的命令:
/etc/init.d/mysql start
2、关闭Mysql的命令:
/etc/init.d/mysql shutdown
3、重启Mysql的命令:
/etc/init.d/mysql restart
4、创建用户:
grant 权限(all代表所有权限) on database_name.* to userNmae@"%" identified by "Password"
GRANT privileges (columns) ON what TO user IDENTIFIED BY "password" WITH GRANT OPTION
如果创建用户后或者Update Mysql-User表后权限的设置不生效,可以执行flush privileges;就OK!

mysql>grant select,insert,update,delete,create,drop on vtdc.employee to joe@10.163.225.87 identified by '123';
给来自10.163.225.87的用户joe分配可对数据库vtdc的employee表进行select,insert,update,delete,create,drop等操作的权限,并设定口令为123。

mysql>grant all privileges on vtdc.* to joe@10.163.225.87 identified by '123';
给来自10.163.225.87的用户joe分配可对数据库vtdc所有表进行所有操作的权限,并设定口令为123。

mysql>grant all privileges on *.* to joe@10.163.225.87 identified by '123';
给来自10.163.225.87的用户joe分配可对所有数据库的所有表进行所有操作的权限,,并设定口令为123。

mysql>grant all privileges on *.* to joe@localhost identified by '123';
给本机用户joe分配可对所有数据库的所有表进行所有操作的权限,并设定口令为123。

5、导入数据:
在mysql的命令行 source /root/daoru.sql;

6、Linux下解决Mysql数据库大小写的问题:
修改/etc/my.cnf文件,在[mysqld]下加一行:lower_case_table_names=1 (修改完后需要重启动mysql才能生效)
如果/etc下没有my.cnf文件,就把/usr/share/mysql目录下的my-medium.cnf拷贝到/etc目录下,重命名为my.cnf,然后再修改,最后重启Mysql就OK了.可以在Mysql的命令行检查当前的设置是否区分大小写:

mysql> show variables like '%case_table%';

+------------------------+-------+

| Variable_name          | Value |

+------------------------+-------+

| lower_case_table_names | 1     |

+------------------------+-------+
(0:区分;1:不区分)

7、自动启动
1)察看mysql是否在自动启动列表中
[root@test1 local]# /sbin/chkconfig –list
2)把MySQL添加到你系统的启动服务组里面去
[root@test1 local]# /sbin/chkconfig – add mysql
3)把MySQL从启动服务组里面删除。
[root@test1 local]# /sbin/chkconfig – del mysql

8、修改Mysql字符编码:

打开配置文件/etc/my.cnf(修改完后需要重启动mysql才能生效)
在[client] 添加   default-character-set=utf8 默认字符集为utf8
在[mysqld] 添加   default-character-set=utf8 默认字符集为utf8
init_connect='SET NAMES utf8' (设定连接mysql数据库时使用utf8编码,以让mysql数据库为utf8运行)

mysql> show variables like 'character_set%';
+--------------------------+----------------------------+
| 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/ |
+--------------------------+----------------------------+

9、查看Mysql数据库里已经创建好的存储过程和存储函数:

SHOW PROCEDURE STATUS
SHOW FUNCTION STATUS
查看某个存储过程的代码:show create procedure status

对于存储过程,如果是root用户创建的,其他用户则无法访问,可以用如下的方式来解决:
mysql> SHOW CREATE PROCEDURE `database`.`procedure_name`\G
mysql> GRANT select ON mysql.proc to user@'host' IDENTIFIED BY 'passwd';
注意:identified by 'passwd' 的用途是修改密码,如果不想修改密码的话就不要加这句话.

10、查看表结构:desc table_name;
Linux下查看到3306端口的tcp链接:netstat -an | grep 3306
Mysql命令行下查看连接池的链接:show processlist
Linux下远程链接Mysql数据库:mysql -h192.168.1.1 -u -p

11、mysql的用户权限

首先是用户的创建,可以用grant
GRANT ALL PRIVILEGES ON *.* TO 'monty'@'localhost' IDENTIFIED BY 'some_pass' WITH GRANT OPTION;

也可以直接插入:
INSERT INTO user (Host,User,Password) VALUES('localhost','dummy',PASSWORD('some_pass'));
FLUSH PRIVILEGES;

linux

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template