欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

mysql在ubuntu上的安装过程

程序员文章站 2022-06-13 22:57:29
...

1、安装mysql-server:

hadoop@stcn501a0166:~$ mysql
程序 'mysql' 已包含在下列软件包中:
* mysql-client-core-5.5
* mariadb-client-core-5.5
* mysql-client-core-5.6
* percona-xtradb-cluster-client-5.5
请尝试:sudo apt-get install <选定的软件包>
hadoop@stcn501a0166:~$ sudo apt-get install mysql-server
[sudo] password for hadoop:
正在读取软件包列表... 完成
正在分析软件包的依赖关系树
正在读取状态信息... 完成

 说明:遇到输入的地方输入Y,过程中需要设置root用户的密码,设置时记住密码

2、root用户登录:

hadoop@stcn501a0166:~$ mysql -u root -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 48
Server version: 5.5.44-0ubuntu0.14.04.1 (Ubuntu)

Copyright (c) 2000, 2015, 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>

 3、查看系统中的数据库:

mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
+--------------------+
3 rows in set (0.00 sec)

mysql>

 4、新建测试用数据库:

mysql> create database example;
Query OK, 1 row affected (0.00 sec)

mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| example |
| mysql |
| performance_schema |
+--------------------+
4 rows in set (0.00 sec)

mysql>

 5、创建新的用户帐号:

mysql> create user 'mzuser'@'localhost' identified by '123456';
Query OK, 0 rows affected (0.00 sec)
mysql> grant all on example.* To 'mzuser'@'localhost';
Query OK, 0 rows affected (0.00 sec)

 说明:给用户赋予在example数据库上的权限

6、使用新用户登录

hadoop@stcn501a0166:~$ mysql -u mzuser -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 49
Server version: 5.5.44-0ubuntu0.14.04.1 (Ubuntu)

Copyright (c) 2000, 2015, 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> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| example |
+--------------------+
2 rows in set (0.00 sec)

mysql>

 7、修改用户访问的数据库并查看库中表

mysql> use example
Database changed
mysql> show tables;
Empty set (0.00 sec)

mysql> exit

 由于新创建的库中没有任何表,所以显示为empty

8、退出登录并关闭数据库服务:

     sql>exit

     ~$sudo /etc/init.d/mysql stop

9、测试创建表(使用新建用户登录,use example数据库)

mysql> create table CmsUser(
> userid int(8) not null auto_increment primary key,
>username varchar(20) not null,
> password varchar(20),
> area varchar(10),
>deptrole varchar(10));
Query OK, 0 rows affected (0.06 sec)

mysql> show tables;
+-------------------+
| Tables_in_example |
+-------------------+
| CmsUser |
+-------------------+
1 row in set (0.00 sec)

 

相关标签: mysql 安装